TypeScript and field initializers

前端 未结 14 2254
暖寄归人
暖寄归人 2020-11-30 16:49

How to init a new class in TS in such a way (example in C# to show what I want):

// ... some code before
return new MyClass { Field         


        
14条回答
  •  醉梦人生
    2020-11-30 17:36

    if you want to create new instance without set initial value when instance

    1- you have to use class not interface

    2- you have to set initial value when create class

    export class IStudentDTO {
     Id:        number = 0;
     Name:      string = '';
    
    
    student: IStudentDTO = new IStudentDTO();
    

提交回复
热议问题