vue-strict-prop
TypeScript icon, indicating that this package has built-in type declarations

0.3.6 • Public • Published

vue-strict-prop

Build Status

strict-typed prop builder for Vue component

Example

import Vue, { VNode } from "vue";
import p from "vue-strict-prop";
 
const MyComponent = Vue.extend({
    props: {
        // equivarent to { type: String, required: true, validator: v => v.length >= 3 }.
        title: p(String).validator(v => v.length >= 3).required,
 
        // equivarent to { type: String, required: false }.
        // `this.description` is statically typed as `string | undefined`.
        description: p(String).optional,
 
        // equivarent to { type: [String, Number], required: true }.
        // `this.height` is statically typed as `string | number`.
        height: p(String, Number).required,
 
        // equivarent to {
        //      type: String,
        //      required: false,
        //      default: "black",
        //      validator: v => v === "black" || v === "blue" || v === "red"
        //  }.
        // `this.color` is statically typed as `"black" | "blue" | "red"`.
        color: p.ofStringLiterals("brack", "blue", "red").default("black"),
 
        // equivarent to { type: Array, required: true }.
        // `this.buttons` is statically typed as `Array<string>`
        buttons: p.ofArray<string>().required
 
        // equivarent to { required: true }.
        // `this.ctx` is statically typed as `TContext`
        ctxp.ofType<TContext>().required
 
    },
    render(h): VNode {
        /* snip */
    }
});

More examples can be found in here.

Readme

Keywords

Package Sidebar

Install

npm i vue-strict-prop

Weekly Downloads

866

Version

0.3.6

License

MIT

Unpacked Size

14.5 kB

Total Files

10

Last publish

Collaborators

  • iwata0303