You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generic type of superclass cannot be inferred from function call on a subclass #20348
classEvented<M>{// protected __typeMap__?: M; on<KextendskeyofM>(type: K,listener: (event: M[K])=>void){}}functionon<M,KextendskeyofM>(target: Evented<M>,type: K,listener: (event: M[K])=>void){}interfaceEventMap{change: {type: 'change';};}conste=newEvented<EventMap>();e.on('change',(event)=>{});// type of event: { type: 'change' }on(e,'change',(event)=>{});// type of event: { type: 'change' }classSubEventedextendsEvented<EventMap>{}consts=newSubEvented();s.on('change',(event)=>{});// type of event: { type: 'change' }on(s,'change',(event)=>{});// type of event: M[K]
Expected behavior: event is inferred as { type: 'change' } on line 20 (last line)
Actual behavior:
Line 20 is flagged as an error:
error TS2345: Argument of type '"change"' is not assignable to parameter of type 'never'.
Currently, the only way to get line 20 to work as expected is to uncomment line 2.
it is worth noting that the inference here for M will not be EventMap, since the there is no manifestation for this type to be inferred from. however, with #20126, M will be inferred from the use M[K] to be a type with a property named K (or "change" in the example above).
Activity
mhegazy commentedon Nov 29, 2017
Should be fixed by #20126
mhegazy commentedon Nov 29, 2017
it is worth noting that the inference here for
Mwill not beEventMap, since the there is no manifestation for this type to be inferred from. however, with #20126,Mwill be inferred from the useM[K]to be a type with a property namedK(or "change" in the example above).RyanCavanaugh commentedon Dec 16, 2021
This is the intended behavior -- there is no inference site for
M