TypeScript Version: 2.4.0
Code
interface IPage {
method: (ev: string | number) => any;
}
class Page implements IPage {
method(e): any {
// this "e" is implicitly any
}
}
let x = new Page();
x.method = (e) => {
// this "e" is inferred to be 'string | number'
}
Expected behavior:
The method override in Page should be inferred type string | number.
Actual behavior:
The method override in Page is implicitly the any type.
This seems like it should instead infer the parent type, because
- instance overrides already have this sort of inference (see the Contextual Type example about
window.onmousedown), and
- if the class's override signature was something like
method(e: object): any, there would be an error that says the class wasn't matching the interface's signature. (Class 'Page' incorrectly implements interface 'IPage'.)
TypeScript Version: 2.4.0
Code
Expected behavior:
The method override in
Pageshould be inferred typestring | number.Actual behavior:
The method override in
Pageis implicitly theanytype.This seems like it should instead infer the parent type, because
window.onmousedown), andmethod(e: object): any, there would be an error that says the class wasn't matching the interface's signature. (Class 'Page' incorrectly implements interface 'IPage'.)