I set the value of 'noImplicitAny' true. I thought that 'any' should be applied to the return value of a function, but it was not actually. No errors occurred.
Why doesn't noImplicitAny
apply to the return value of the function?
From tsconfig.json
:
{
"noImplicitAny": true
}
Not Any noImplicitAny
errors be raised on function below.
function abc () {
return '1'
}
Should it be like this?
function abc (): any {
return '1'
}
Thanks.
The compiler tries to infer as much as it can. noImplictAny
will only cause an error if the compiler can't infer the type of something, it will not force you to specify all type annotations.
In your case, the compiler can easily infer the return type of the function as number
and it does so (if you hover over the function in your ide you should see the return as number)
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