Description
TypeScript Version: 3.7.4, 3.8.0-dev.20200115
Search Terms: generic inferred any 3.7
Code
class FieldEvent<T> {
constructor(readonly field: T) { }
}
class Field {
listen<T extends FieldEvent<Field>>(type: new (...args: any[]) => T, listener: (event: T) => void): void { }
}
let field = new Field();
field.listen(FieldEvent, (event) => event.field);
// TS 3.7: event: FieldEvent<any>, so event.field: any
// Up to TS 3.6: event: FieldEvent<Field>, so event.field: Field
Expected behavior:
event
inferred as FieldEvent<Field>
(was the case up to TS 3.6).
Actual behavior:
event
inferred as FieldEvent<any>
since TS 3.7. Still the case with 3.8.0-dev.20200115.
Playground Link:
http://www.typescriptlang.org/play/index.html#code/MYGwhgzhAEBiCWBTEATAogN0QOwC4B4AVAPmgG8Aoaa6YAe2wlwCcBXYXO5gCmcTBQMQAT2gAzJKgBc0QgEpy0AL4UVFUJBgJkKclRoh4THEWiIAHrhwotk9Fjz5tqYsW65hAB0QzsiAO7Q3AB0oWDMAOYQMmDYwgDaALoKALykhAA00IbGfswy3IgOuDLy0GnQGHTwKHIyVTWKKmogiLjiduXQfoHOKNxyANwUEjrBOVbY3H2YOLhZhcWppEVzwaOoQxQA9NuyAMrQAMzBAOwyq3gyM8X4scLEWRB0ZsXrdjFxO3sAqp7QnAOx2CADYLsVrnZZo4+o9oM9XmsNihIToKEA
(Edit: playground link to official site, not beta).
Related Issues: