Skip to content

never as keyof tuples/arrays behaves the same as number #55841

Open
@kristiannotari

Description

@kristiannotari

🔎 Search Terms

tuple keyof never, tuple[never], array keyof never

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about this issue

Versions I tried:

  • 5.2.2
  • nightly (playground)

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.0-dev.20230923#code/C4TwDgpgBAglC8UDeBfA2gOwgNwgJwF0oB6YqQUHIotc8AoUSKAIQWSgEMAuKAZ2DwCWGAOZR01fEVIUqOfPXDQAwqzQFMcwiTKUJdBtAAiqvoJHq9UsoBlyXvyHCFjAKKtTDtRppWot9yKdoADFWAAp-UQAfKgBXAFsAI3wASk9LKG1fOzMo2MT8IA

💻 Code

type A = {}[never] // ✅ never
type B = { a: string }[never] // ✅ never
type C = [][never] // ✅ never
type D = [string][never] // ❌ string
type E = string[][never] // ❌ string
type F = (string | number)[][never]  // ❌ string | number

🙁 Actual behavior

After using a never key on tuples/arrays you get back the entirety of the tuple/array elements type.

🙂 Expected behavior

After using a never key on tuples/arrays you get back never, as when dealing with objects.

Additional information about the issue

Not sure if this has historical reasons to behave like it does, but couldn't find any specific info about it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Possible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions