Reputation: 155
Here is a TypeScript snippet that compiles just fine (using 1.5.3).
function alertNumber(a: number) {
alert(a + 1);
}
var x:any = "string";
alertNumber(x);
How is it possible that a function requesting parameter of a certain type can be called with argument of type any
?
Upvotes: 12
Views: 5249
Reputation: 106640
It's because you opt out of type-checking when you use any
types.
[Sometimes] we want to opt-out of type-checking and let the values pass through compile-time checks. To do so, we label these with the 'any' type. - Handbook
To avoid troubles with any
:
--noImplicitAny
compiler option (or turn off Allow implicit any types
in Visual Studio).any
types except where necessary (Ex. var x: any
)Upvotes: 9