-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
Discriminated union
π Version & Regression Information
- This changed between versions 4.5.5 and 4.6.4
β― Playground Link
Playground link with relevant code
π» Code
class Model {
constructor(public flag: boolean) {}
}
type DiscriminatedUnion = { flag: true } | { flag: false };
class A<T extends DiscriminatedUnion> {
constructor(public model: T) { }
}
// Uncomment the two lines below to get rid of the compiler error:
// function foo(_model: DiscriminatedUnion) { }
// foo({} as Model);
class B extends A<Model> { } // Type 'Model' is not assignable to type '{ flag: false; }'.
π Actual behavior
Class A
doesn't accept Model
as generic parameter with the following error:
Type 'Model' is not assignable to type '{ flag: false; }'.
Types of property 'flag' are incompatible.
Type 'boolean' is not assignable to type 'false'.
The basic example above hadn't emitted any errors prior to v4.6. Furthermore, if you uncomment the code that declares and executes function foo
, the compiler error vanishes.
π Expected behavior
The code is compilable in 4.6+ without any workarounds.
whzx5byb
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue