1.

How to specify optional properties in TypeScript?

Answer»

An OBJECT TYPE can have zero or more optional properties by adding a ‘?’ after the property name. 

let pt: { x: number; y: number; Z?: number } = { x: 10, y: 20};console.log(pt);

In the example above, because the property ‘z’ is marked as optional, the compiler won’t complain if we don’t provide it during the initialization.



Discussion

No Comment Found