Suppose the following simplified TypeScript snippet:
interface MyInterface {
callbackLambda: (value: string) => void;
callbackFunction(value: string): void;
}
type MyType = "MyValue";
const myObject: MyInterface = {
callbackLambda: (value: MyType): void => {
console.log(value);
},
callbackFunction: (value: MyType): void => {
console.log(value);
}
};
myObject.callbackLambda("MyValue");
myObject.callbackFunction("MyValue");
This code doesn't compile because TypeScript says:
Type '(value: MyType) => void' is not assignable to type '(value: string) => void'.
Types of parameters 'value' and 'value' are incompatible.
Type 'string' is not assignable to type '"MyValue"'.
So, it looks like the function definition compiles fine but the arrow function definition doesn't.
Here's a repro playground.
I couldn't find the information in the documentation and my initial thought was that it should compile fine. Can anybody explain (and find the relevant documentation) why the function definition compiles fine and not the arrow function in this case?