Skip to content

Why must two methods with the same name be identical when inheriting them from different interfaces? #2871

Closed
@benjamin-hg

Description

@benjamin-hg
declare class Super {
    set(property:string, value:any);
}

declare class SubA extends Super {
    set(property:"name", value:string);
    set(property:string, value:any); // don't know why this is needed, as it should be inherited
}

declare class SubB extends Super {
    set(property:"size", value:number);
    set(property:string, value:any); // okay, I repeat myself.
}


interface Both extends SubA, SubB {

}

Gives me:
Error:(16, 15) TS2320: Interface 'Both' cannot simultaneously extend types 'SubA' and 'SubB'.
Named properties 'set' of types 'SubA' and 'SubB' are not identical.

I'm working with Dojo, where SubA and SubB are two Widgets and Both is the type of a mixin.

Ironically, this prevents the error:

interface Both extends SubA, SubB {
    set(property:string, value:any); 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions