Skip to content

Assign to union with over 25 items gives errorΒ #43283

Closed

Description

@cevek

Bug Report

πŸ”Ž Search Terms

union 25

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type A = { kind: 'AA' | 'AB' | 'AC' | 'AD' | 'AE' | 'AF' | 'AG' | 'AH' | 'AK' };
type B = { kind: 'BA' | 'BB' | 'BC' | 'BD' | 'BE' | 'BF' | 'BG' | 'BH' | 'BK' };
type C = { kind: 'CA' | 'CB' | 'CC' | 'CD' | 'CE' | 'CF' | 'CG' | 'CH' | 'CK' }; // if remove 2 last items then ok
type ABC = A | B | C;

declare const kind: ABC['kind'];
const x: ABC = { kind }; // error

πŸ™ Actual behavior

Types of property 'kind' are incompatible.

πŸ™‚ Expected behavior

no error

Activity

  1. changed the title [-]Union with over 25 items gives error[/-] [+]Assign to union with over 25 items gives error[/+] on Mar 17, 2021
  2. MartinJohns commented on Mar 17, 2021

    @MartinJohns
    Contributor

    Duplicate of #40803. Used search terms: union 25. I also found this issue using your search terms: big union.

    This is a hard coded intentional limit.

  3. MrNovado commented on Mar 17, 2021

    @MrNovado

    Martin Johns (@MartinJohns) Thanks! Is there any known and accepted workaround for this? And are there any plans to up the limit in the near future?

  4. MartinJohns commented on Mar 17, 2021

    @MartinJohns
    Contributor

    I don't know of any workaround, and I'm not aware of any plans to increase this limit. But that would be up to the TypeScript team, of course.

    A good idea is to subscribe to the existing issue, so you get notified if something is changing.

  5. RyanCavanaugh commented on Mar 17, 2021

    @RyanCavanaugh
    Member

    We don't plan to change this. There are a decent number of cases where we try this structural expansion but it doesn't work, so limiting the cost of that happening is important.

  6. cevek commented on Mar 17, 2021

    @cevek
    Author

    It will be good if there will be right error about this limit, not incompatible error

  7. RyanCavanaugh commented on Mar 17, 2021

    @RyanCavanaugh
    Member

    It will be good if there will be right error about this limit, not incompatible error

    It's not clear how to do this. "It's possible that a finite expansion of all possible inhabitants of each type may result in a subset" is going to be true a decent amount of time yet would be very confusing.

  8. jogibear9988 commented on Mar 19, 2021

    @jogibear9988

    Wouldn't it be desiarable to add a tsconfig parameter for the limit?

  9. typescript-bot commented on Mar 22, 2021

    @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.

  10. denbkh commented on Oct 7, 2025

    @denbkh

    It will be good if there will be right error about this limit, not incompatible error

    It's not clear how to do this. "It's possible that a finite expansion of all possible inhabitants of each type may result in a subset" is going to be true a decent amount of time yet would be very confusing.

    Ryan Cavanaugh (@RyanCavanaugh) right now the error message is very confusing. The compiler should output in error message that the hardcoded limit is reached.

  11. RyanCavanaugh commented on Oct 7, 2025

    @RyanCavanaugh
    Member

    Denis Bakharev (@denbkh) you would see that error all the time in cases where even if the limit were Infinity, the assignment would still fail

  12. 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