Every now and then I turn on the NoImplicitAny compiler switch and try and pick out all the implicit any's I have in my codebase. (Unfortunately I can't have it on the whole time as a good portion of 3rd party typing files also contain implicit any's - but
that's another story.)
I just spotted something unusual. It seems that there are occasions where the compiler thinks that a variable is an implicit any but the tooling in Visual Studio 2012 disagrees. While the compiler says:
error TS7012: Parameter 'event' of lambda function implicitly has an 'any' type.
Visual Studio is correctly picking up the type - if you take a look at the enclosed screenshot you can see this in action.
The examples where I have seen this happen have all been using the
methods which are part of DefinitelyTyped's Knockout typings at present:
arrayForEach<T>(array: T, action: (item: T) => void): void;
arrayForEach(array: any, action: (any) => void ): void;
arrayFirst<T>(array: T, predicate: (item: T) => boolean, predicateOwner?: any): T;
arrayFirst(array: any, predicate: (item) => boolean, predicateOwner?: any): any;
arrayFilter<T>(array: T, predicate: (item: T) => boolean): T;
arrayFilter(array: any, predicate: (item) => boolean): any;
arrayMap<T, U>(array: T, mapping: (item: T) => U): U;
arrayMap(array: any, mapping: (item) => any): any;
As you can see, there are both genericised and non-genericised overloads available. The Visual Studio tooling appears to be selecting the generic overload and the compiler the non-generic overload in each case.
When I experimented with removing the non-generic overloads from Knockout typings I found I was able to get the Visual Studio and the compiler to behave the same way. (And since there was only 1 overload available in each case after my tweaks I guess that makes
This isn't a major issue but I thought I'd flag it up - it would be great if by default both the compiler and Visual Studio behaved the same way when it comes to selecting overloads.