Skip to content

Union of array literal types has uncallable methodsΒ #62645

Closed as not planned
Closed as not planned

Description

@vegerot

πŸ”Ž Search Terms

"array literal method never"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about distributive conditional types.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEEQBd5QFzwNoCIQDscBdeAH2z3wFoBxAIWLIoJwBp4cBLYKgSQBFG5XC3Y5kACyoAVABJDmhMQFsAzlQCyATQUilHAG6cqANQByunAC8pAYQslhlWgzEhVlgi7YdQVfgCintT0PjgAZjDB3mKcyHzSwWHuVAAsAIwAnElisDkcAA7xdABKxADcAFBQAHSc+JAArqCqABSUOACUlUA

πŸ’» Code

declare let a: ["en"] | ["en-GB"] | ["en", "id-ID"] | ["zh-CN"];
a.includes("en");

πŸ™ Actual behavior

Error:

Argument of type '"en"' is not assignable to parameter of type 'never'.

πŸ™‚ Expected behavior

No error

Additional information about the issue

The type of .includes is Array<T>.includes(searchElement: never, fromIndex?: number | undefined): boolean.

You'd think the type of searchElement would be "en" | "en-GB" | "id-ID" | "zh-CN", or at least string.

Activity

  1. MartinJohns commented on Oct 21, 2025

    @MartinJohns
    Contributor

    This is working as intended. When calling a method on a union, your parameters become an intersection. The first parameter of ["en"].includes() is typed "en", and of ["en-GB"].includes() it's typed "en-GB". The intersection "en" & "en-GB" results in never.

    This is another duplicate of #26255 / #14520.

  2. RyanCavanaugh commented on Oct 22, 2025

    @RyanCavanaugh
    Member

    πŸ€– Thank you for your issue! I've done some analysis to help get you started. This response is automatically generated; feel free to πŸ‘ or πŸ‘Ž this comment according to its usefulness.

    Similar Issues

    Here are the most similar issues I found

    If your issue is a duplicate of one of these, feel free to close this issue. Otherwise, no action is needed.

  3. typescript-bot commented on Oct 25, 2025

    @typescript-bot
    Contributor

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

  4. locked as resolved and limited conversation to collaborators on Jan 7, 2026
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