proxy-typer-class-example-with-cast

node v8.17.0
version: 1.0.0
endpointsharetweet
const {ProxyTyper, AsyncFunction} = require("proxy-typer@0.0.15"); class Test { constructor(value, number) { this.value = value; this.number = number; } setValue(val, val2) { return {val, val2} } async getValue() { return this.number.toString(); } } Test.propTypes = { value: {type: String, cast: (v)=> v ? v.toString() : v, required: false}, // is equal to {type: String} number: Number, // if prop isn't required then {type: Number, required: false} setValue: {type: Function, args: [Number, String], return: Object, cast: (v1,v2)=> [Number(v1), String(v2)]}, // if function need to return value then add {return: [Type]} getValue: {type: AsyncFunction, return: String} }; const TestModel = ProxyTyper(Test); const test = new TestModel("test", 45); test.value = null; test.setValue("35","w45"); test.getValue();
Loading…

no comments

    sign in to comment