Skip to content

Conditional type unexpectedly non-distributive with neverΒ #57343

Closed
@rotu

Description

@rotu

πŸ”Ž Search Terms

never, intersection, contradiction

πŸ•— Version & Regression Information

⏯ Playground Link

Workbench Repro

πŸ’» Code

type IsNumber<T> = T extends number ? true : false

type Conflicted = {x:true} & {x:false} // never
//   ^?

type Ex1 = IsNumber<Conflicted> // true. Should be never 
//   ^?
type Ex2 = IsNumber<never>
//   ^?

// Conflicted starts behaving like `never` again when distributivity is forced by putting it in a union
type Ex3 = IsNumber<"OEEE" | Conflicted> // false (boolean in TypeScript 4.6.4)
//   ^?
type Ex4 = IsNumber<1 | Conflicted> // true
//   ^?

πŸ™ Actual behavior

Ex1 is true.

πŸ™‚ Expected behavior

IsNumber<Conflicted> should be never. This is a distributive conditional.

Additional information about the issue

This also manifests as ReturnType<T> being unknown when T is a conflicted intersection.

Originally submitted in #57210 which was overly broad.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions