typescript / beginner
Snippet
Optional Interface Properties
Using the question mark (?) makes a property optional, meaning it does not have to be present when creating an object of that type.
snippet.ts
1
2
3
4
interface Config {host: string;port?: number;}
Breakdown
1
port?: number
Indicates that 'port' is optional and can be a number or undefined.