Skip to content

Generic type of superclass cannot be inferred from function call on a subclass #20348

Description

TypeScript Version: 2.7.0-dev.20171129

Code

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions