Skip to content

Overload Signature Is Not Compatible For Inherited Type Function Parameter #17162

Closed
@daryllabar

Description

@daryllabar

TypeScript Version: 2.4.1

Code

// A *self-contained* demonstration of the problem follows...
class Animal {
    a: string;
}

class Dog extends Animal {
    b: string;
}

function test(func: (p: Dog) => any): any;
function test(func: (p: Animal) => any): any;
function test(func: (p: Animal) => any): any {

    return undefined;
}

Expected behavior:
No TS2394 Compiler error

Actual behavior:
a TS2394 Compiler error for this line:

function test(func: (p: Dog) => any): any;

Changing function definition the below resolves the compile error:

function test(func: (p: any) => any): any {

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions