Closed
Description
Bug Report
π Search Terms
Union types expansion, generic constraints
π Version & Regression Information
4.6, works fine in 4.5
β― Playground Link
Playground link with relevant code
π» Code
type UnionType = {name: 'A'} | {name: 'B'}
type NotUnionType = {name: 'A' | 'B'}
type MyType<T extends UnionType> = number
// Errors here, because NotUnionType is presumably not assignable to UnionType
let d: MyType<NotUnionType>
// No error, because NotUnionType is assignable to UnionType
let check: NotUnionType extends UnionType ? true : false
= true
The error doesn't reproduce, however, if I change the order of lines:
let check: NotUnionType extends UnionType ? true : false
= true
// No error
let d: MyType<NotUnionType>
π Actual behavior
Error when instanciating MyType<NotUnionType>
π Expected behavior
No error. Also error trace seems to be missing some entries in the beginning (I would expect it to start with something like NotUnionType does not satisfy the constraint UnionType
whereas in actuality is starts with Type 'NotUnionType' is not assignable to type '{ name: "B"; }'
).