With
"noImplicitAny": true
TypeScript will give the error:
Parameter 'x' implicitly has an 'any' type
for
.do(x => console.log(x));
and error
',' expected
for:
.do(x: any => console.log(x));
Arrow functions can never have duplicate named parameters, whether in strict or non-strict mode.
ES6 version of TypeScript provides an arrow function which is the shorthand syntax for defining the anonymous function, i.e., for function expressions. It omits the function keyword. We can call it fat arrow (because -> is a thin arrow and => is a "fat" arrow).
Set the return type of an arrow function in TypeScript # You can set the return type of an arrow function in TypeScript right after its parameters, e.g. const greet = (name: string): string => {} . Once a function's return type is set, the type checker alerts us if the function returns a value of a different type.
In a type position, => defines a function type where the arguments are to the left of the => and the return type is on the right. So callback: (result: string) => any means " callback is a parameter whose type is a function.
After some searching I found the correct way to define a type for the parameter is to add parentheses:
.do((x: any) => console.log(x));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With