Reputation: 1895
In the sample code below, when implementing MyInterface
...
any
If it can detect an incorrect type, why can it not infer the correct type?
interface MyInterface<T = any> {
myFunction(input: T): void;
}
class MyClass implements MyInterface<number> {
// input inferred as 'any'
myFunction(input) {}
}
class MyClass2 implements MyInterface<number> {
// Type 'number' is not assignable to type 'string'
myFunction(input: string) {}
}
Upvotes: 0
Views: 25
Reputation: 30909
This is a little more complicated than it looks in general. There is an open suggestion.
Upvotes: 1