Search code examples
typescriptgoogle-closure-compilerflowtype

Why does typescript not allow optional parameters before required parameters?


i am using typescript for my project and noticed while writing a definition file that openui5 occasionaly uses optional parameters before required parameters. e.g. // Defines a Javascript module with its name, its dependencies and a module value or factory. define(sModuleName?, aDependencies?, vFactory, bExport?); Typescript, Flow Type and the Closure Compiler all require a parameter list in this form: ParameterList: RequiredParameterList OptionalParameterList RestParameter RequiredParameterList , OptionalParameterList RequiredParameterList , RestParameter OptionalParameterList , RestParameter RequiredParameterList , OptionalParameterList , RestParameter

However, could this construct not be seen as equivalent to three overloaded functions, i.e.

define(vFactory, bExport?);
define(aDependencies, vFactory, bExport?);
define(sModuleName, aDependencies, vFactory, bExport?);

Solution

  • However, could this construct not be seen as equivalent to three overloaded functions

    It could. But all language features start at -100. And there are not enough use cases to certify the complication.