Short answer: use value ? OR default - both options will be optional.
Longer answer: If you look in the TypeScript Language Specification document, you can find many details about the language syntax.
Section 3.7.2 describes call signatures, i.e. the syntax used to call functions and constructors, etc.
Section 3.7.2.2 specifies the parameters associated with the call.
It defines additional parameters as:
PublicOrPrivateopt ID? Typeannotationopt
Type ID PublicOrPrivateopt TypeAnnotationopt Initialiser
We see either the use of '?' OR, providing a default value, marks the parameter as optional.
So, to fix a compiler error, you can simply remove the '?' and leave the default value, and it will remain as an optional parameter as you plan.
AndyJ
source share