Skip to content

Union types are not expanded properly when checking if type satisfies generic constraintΒ #49778

Closed
@jabuj

Description

@jabuj

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"; }').

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions