Tip - Inline field assignment form Constructor in TypeScript

typescript
Back

Example

Instead of this way

class Person {
private id: string;
private name: string;
constructor(id: string, name: string) {
this.id = id || 0;
this.name = name;
}
}

Use this way, this is much clean and un-necessary typing efforts.

class Person {
constructor(private id: string = 0, private name string) {}
}

Thanks!

MIT © Mohan Dere.
-