Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript lambda functions with optional parameters

Tags:

typescript

I am having problems when defining a lambda function that accepts an optional parameter. The strange part is that if I use the full "function" syntax the anonymous function works, but the lambda shorthand/arrow syntax produces errors such as the following:

  • The name 'a' does not exist in the current scope
  • Supplied parameters do not match any signature of call target
  • Expected ')'

Example:

(function (a, b?) => { console.log(a, b); })("a"); // OK
((a, b?) => { console.log(a, b); })("a", "b");     // Errors
((a, b) => { console.log(a, b); })("a", "b");      // OK
like image 860
nxn Avatar asked Dec 16 '22 18:12

nxn


1 Answers

This is a bug in the compiler and is getting fixed right now [v0.8]. Lambdas currently give error messages with optional and rest parameters. Please use the long function syntax if this is a blocking issue.

like image 174
Murat Sutunc Avatar answered Dec 28 '22 01:12

Murat Sutunc