Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用typescript中的类验证器创建自定义函数和默认属性_Javascript_Node.js_Typescript_Class Validator_Sequelize Typescript - Fatal编程技术网

Javascript 使用typescript中的类验证器创建自定义函数和默认属性

Javascript 使用typescript中的类验证器创建自定义函数和默认属性,javascript,node.js,typescript,class-validator,sequelize-typescript,Javascript,Node.js,Typescript,Class Validator,Sequelize Typescript,如何在类验证器DTO中创建自定义函数,以及如何在从DB检索对象后调用它们。另外,如何在插入数据时应保存的同一类中声明默认属性 我有一个带有类验证器的DTO类: export class CustomDTOClass { @IsString() propOne: string | null; @IsString() propTwo: string | null; <how can I make this default with value tr

如何在类验证器DTO中创建自定义函数,以及如何在从DB检索对象后调用它们。另外,如何在插入数据时应保存的同一类中声明默认属性

我有一个带有类验证器的DTO类:

export class CustomDTOClass {

    @IsString()
    propOne: string | null;

    @IsString()
    propTwo: string | null;

    <how can I make this default with value true for eg. with any decorator?>
    readonly someDefaultProp: boolean = true;

    <this function doesn't print when an object of CustomDTOClass is retrived from DB>
    public print(name: string) {
        console.log('HELLO :' + name);
        console.log('YOUR PROPS ONE:' + this.propOne);
        console.log('YOUR PROPS TWO:' + this.propTwo);
    }

    constructor(propOne: string, propTwo: string) {
        this.propOne = propOne;
        this.propTwo = propTwo;
    }
}
在重试时,调用
print()
无效

const customDTO = await CustomModel.findByPk(1);
customDTO.print('JOE');
它抛出:

TypeError: customDTO.print is not a function

我做错了什么?如何在类验证器中创建带有注释的默认值?

能否粘贴CustomModel的外观?
TypeError: customDTO.print is not a function