Function expression, which lacks return-type annotation, implicitly has an 'any' return type.
Hi there...
I am using TS version 1.7.4...
all of a sudden I started getting the error:
Error TS7011 Function expression, which lacks return-type annotation, implicitly has an 'any' return type.
the offending line of code is:
setTimeout(() => this.alertMessage = null, 2000);
not sure why it suddenly started happening... I have been running this version for a while now... anyway... I don't understand why I am getting this error... the field "alertMessage" is defined as such:
alertMessage: string;
I guess I am wondering why the compiler is inferring "any" instead of "string"
Thank you
The issue is that the type of an assignment expression is always the type of the right operand, which in this case is null (which is widened to an implicit any).
We should fix this by adding an overload to setTimeout
declare function setTimeout(handler: (...args: any[]) => any, timeout: number): number;
@RyanCavanaugh ... thanks
should not the return type be void? the result is ignored by the caller.
i meant the return type of the call back, i.e.:
declare function setTimeout(handler: (...args: any[]) => void, timeout: number): number;