-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
Trying to convert function overloads to union type, I'm getting errors.
Here is a very simple code that shows the error:
class Animal { run() {} }
class Cat extends Animal {}
class Dog extends Animal {}
function run(a: Animal) {
a.run();
}
function f<T extends Cat | Dog>(a: T) {
a.run(); // OK.
run(a); // Argument of type 'T' is not assignable to parameter of type 'Animal'.
}I don't understand the difference TS makes between a.run() and run(a).
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue