Category Archives: TypeScript

TypeScript : Functions : Optional Parameters

Problem

I need to allow a parameter to be optional in TypeScript. Optional parameters in TypeScript have to be declared.

Answer

Use “?” next to the parameter name to allow the parameter to be optional. The optional parameter must come last in the parameter list but before a REST parameter.

Example

MyFunction(myString: string, myNumberOpt?: number) { ... }