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
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();
I suggest an approach that does not require Typescript 2.1:
class Person {
public name: string;
public address?: string;
public age: number;
public constructor(init:Person) {
Object.assign(this, init);
}
public someFunc() {
// todo
}
}
let person = new Person(<Person>{ age:20, name:"John" });
person.someFunc();
key points:
Partial<T>
not required