nxn
nxn

Reputation: 4315

TypeScript lambda functions with optional parameters

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:

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

Upvotes: 5

Views: 9986

Answers (2)

Murat Sutunc
Murat Sutunc

Reputation: 953

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.

Upvotes: 9

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 221004

There's currently a bug with optional parameter annotation in fat arrow lambda expressions.

Upvotes: 3

Related Questions