Skip to content

Removing null and undefined from a Tuple breaks equality #50753

Closed
@zedryas

Description

@zedryas

Bug Report

When trying to remove nils from a Tuple it resolves to an Tuple that do not extends to the identical Tuple (as represented by the compiler)

So in the example below the reult of a type is [a: 1, b?:2] which do not extends the type [a: 1, b?:2] ??

🔎 Search Terms

Identical type - Invalid Equality
tuple optional extends

🕗 Version & Regression Information

Discovered the issue today and it's referenced on the following stackoverflow
I did test it in the playground upto version 4.05 of typescript (syntax breaks in version prior)

⏯ Playground Link

playground

💻 Code

type UnNullify<T extends readonly unknown[]> = {
  [K in keyof T]: Exclude<T[K], null | undefined>
}

type Foo = UnNullify<[a: 1, b?: 2 | undefined]>
//   [a: 1, b?: 2]

type Test = [a: 1, b?: 2] extends Foo ? true : false
//   false ??

🙁 Actual behavior

Two types represented identical by the compiler do not extends each other

🙂 Expected behavior

Expected the two types to extends

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Mapped TypesThe issue relates to mapped typesFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions