Skip to content

Read-only tuple or Set has wrong types in typescript/lib/lib.es2016.array.include.d.ts #53584

Closed

Description

Bug Report

🔎 Search Terms

tuple, readonly, const, includes

🕗 Version & Regression Information

  • This is a crash No
  • This changed between versions - always like this from what I tested
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about includes, tuple
  • I was unable to test this on prior versions because as const was added in version 4

⏯ Playground Link

Playground link with relevant code

💻 Code

const X = ['foo', 'bar'] as const

X.includes('baz')
// Argument of type '"baz"' is not assignable to parameter of type '"foo" | "bar"'.(2345)
// .includes() checks whether a given item is in the tuple, so disallowing any other elements makes the .includes() function useless since all calls that satisfies the types would return true

🙁 Actual behavior

We cannot check whether elements are included in a read-only tuple.

🙂 Expected behavior

We can check whether elements are not included in a read-only tuple.

Activity

  1. changed the title [-]readonly tuple wrong types in typescript/lib/lib.es2016.array.include.d.ts[/-] [+]Read-only tuple wrong types in typescript/lib/lib.es2016.array.include.d.ts[/+] on Mar 30, 2023
  2. MartinJohns commented on Mar 30, 2023

    @MartinJohns
    Contributor

    Duplicate of #14520.

  3. alesmenzel commented on Mar 30, 2023

    @alesmenzel
    Author

    Actually there is even better example

    const set = new Set(['foo', 'bar'] as const)
    set.has('baz')
    // Argument of type '"baz"' is not assignable to parameter of type '"foo" | "bar"'.(2345)

    Playground

  4. changed the title [-]Read-only tuple wrong types in typescript/lib/lib.es2016.array.include.d.ts[/-] [+]Read-only tuple or Set has wrong types in typescript/lib/lib.es2016.array.include.d.ts[/+] on Mar 30, 2023
  5. MartinJohns commented on Mar 30, 2023

    @MartinJohns
    Contributor

    Still a duplicate of the linked issue. :-)

  6. typescript-bot commented on Apr 2, 2023

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  7. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions