Suggestion
TypeScript already supports optional parameters and fields with a question mark.
Why not extend this feature to local variables as well, to allow them having an undefined value, e.g.
Use Cases/Examples
let optional?: number = 123
optional = undefined // allowed
in this case specifying number type is also optional:
This would complete the usage of question mark ? as nullablity/unefineability operator, similar to Kotlin.
Currently, defining an optional variable requires writing a lot of noise, e.g.
let optional: number|undefined = undefined // too verbose
Checklist
My suggestion meets these guidelines:
Suggestion
TypeScript already supports optional parameters and fields with a question mark.
Why not extend this feature to local variables as well, to allow them having an undefined value, e.g.
Use Cases/Examples
in this case specifying
numbertype is also optional:This would complete the usage of question mark
?as nullablity/unefineability operator, similar to Kotlin.Currently, defining an optional variable requires writing a lot of noise, e.g.
Checklist
My suggestion meets these guidelines: