Skip to content

Conditional types produce incorrect typings when used with literal types #54009

@Danchieke

Description

@Danchieke

Bug Report

🔎 Search Terms

Conditional types, union types, literal types, boolean

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about generics, union types and booleans

⏯ Playground Link

Playground link with relevant code

💻 Code

type Test<T> = T extends never ? never[] : T[];

let x: Test<boolean> = [true, false];
let y: Test<3|4|5> = [5,3];

🙁 Actual behavior

Compiles with errors

Type 'boolean[]' is not assignable to type 'false[] | true[]'.
  Type 'boolean[]' is not assignable to type 'false[]'.
    Type 'boolean' is not assignable to type 'false'.
Type '(3 | 5)[]' is not assignable to type '3[] | 4[] | 5[]'.
  Type '(3 | 5)[]' is not assignable to type '3[]'.
    Type '3 | 5' is not assignable to type '3'.
      Type '5' is not assignable to type '3'.

x is of type true[] | false[]
y is of type 3[] | 4[] | 5[]

🙂 Expected behavior

x be of type boolean[]
y be of type (3|4|5)[]
Compiles with no errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions