I have an interface defining an index signature:
interface MethodCollection {
[methodName: string]: (id: number, text: string) => boolean | void;
}
Everything is fine here, any method that I add to such an object will be correctly recognized by their parameter types:
var myMethods: MethodCollection = {
methodA: (id, text) => {
}
}
Now I need to add a type parameter to these functions:
interface MethodCollection {
[methodName: string]: <T>(id: number, text: string, options: T) => boolean | void;
}
The moment I do this, the TypeScript compiler is shutting down:
The text parameter is implicitly of type any
The parameters parameter is implicitly of type any
The id parameter is implicitly of type any
Indeed, IntelliSense can no longer track the correct types, they become implicit any:
var myMethods: MethodCollection = {
methodA: (id, text, options) => {
}
}
? ? Visual Studio 2013, TypeScript 1.6.