I'm writing TypeScript in Visual Studio 2015, with version 2.3.3.0 of the language service extension installed. I have the noImplicitAny parameter set to true in my project's tsconfig.json.
Given this simple example code:
interface ITransformer<TInput, TOutput> {
transform(input: TInput): TOutput;
}
class Input {
name: string;
}
class Output {
name: string;
constructor(name: string) {
this.name = name;
}
}
class Test {
name: string;
}
class Transformer implements ITransformer<Input, Output> {
transform = (input) => new Output(input.name);
}
The TS compiler gives me an error: TS7006: Parameter 'input' implicitly has an 'any' type:
Now, I can easily fix this error by adding a type annotation to the input parameter:
class Transformer implements ITransformer<Input, Output> {
transform = (input: Input) => new Output(input.name);
}
But my question is, why should I have to? It seems to me that the type of that parameter should be inferred from the type of TInput in the implementation of the interface (in this case, Input).
More worryingly, I can happily do this:
class Transformer implements ITransformer<Input, Output> {
transform = (input: Test) => new Test();
}
Which accepts and returns a completely different type not referred to by either of the type parameters, and the compiler seems to have no problem with it...
Coming from a C# background, this just seems wrong. What am I missing?
