Consider the following typescript code:
function eatString(str: string){
console.log(str);
}
const anyObject: any = {
junk: 3425234,
};
eatString(anyObject); // Compiles ok - by why?
eatString({something: "abc"}); // Doesn't compile - as expected
Is there a way to prevent the function eatString(str: string)
from taking an any
argument, either by tsconfig or tslint options or otherwise?
I initially thought that noImplicitAny
might help but after trying it and reviewing the documentation it wasn't what I thought. no-any
isn't an option for me as I still want to be able to use any
in some cases.
If this isn't possible, is there some reason that I'm missing as to why? I haven't been working in typescript/javascript for very long, but I've already been caught out a few times by some issues that this would have prevented.