Skip to content

Extract<T, T> should be the same as T. But It does not behave the same way.Β #46794

@aminbenselim

Description

@aminbenselim

Bug Report

πŸ”Ž Search Terms

Extract
Extract is not pure
Extract behaviour

πŸ•— Version & Regression Information

v4.5.0-beta

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Input = number[] | string[];

type JoinArrays<T> = T extends (infer Element)[] ? Element[] : never;
type JoinArraysWithExtract<T> = Extract<T, T> extends (infer Element)[] ? Element[] : never;

type Output = JoinArrays<Input> // number[] | string[]
type OutputWithExtract = JoinArraysWithExtract<Input> // (string | number)[]

type Wanted = (number | string)[];

πŸ™ Actual behavior

type Extract<T, U> = T extends U ? T : never implies that replacing Extract<T, T> with T should return exactly the same type.

But replacing it in the example I have provided results in two different types.

πŸ™‚ Expected behavior

type JoinArrays<T> = T extends (infer Element)[] ? Element[] : never; 

should be the same as

type JoinArraysWithExtract<T> = Extract<T, T> extends (infer Element)[] ? Element[] : never;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions