TypeScript lambda functions with additional parameters

I'm having problems defining a lambda function that takes an optional parameter. The strange part is that if I use the full syntax of the β€œfunction”, the anonymous function works, but the lambda shortcut / arrow syntax causes errors like the following:

  • The name 'a' does not exist in the current scope
  • The supplied parameters do not match any target call signature
  • 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 
+4
source share
2 answers

This is a compiler error and is being fixed right now [v0.8]. Lambdas currently provides error messages with options and rest options. Please use long function syntax if this is a lock problem.

+9
source

There is currently an error with optional parameter annotation in fat lambda expressions arrow.

+3
source

Source: https://habr.com/ru/post/1438196/


All Articles