Skip to content

Assign to union with over 25 items gives error #43283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cevek opened this issue Mar 17, 2021 · 8 comments
Closed

Assign to union with over 25 items gives error #43283

cevek opened this issue Mar 17, 2021 · 8 comments
Labels
Duplicate An existing issue was already created

Comments

@cevek
Copy link

cevek commented Mar 17, 2021

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

@cevek cevek changed the title Union with over 25 items gives error Assign to union with over 25 items gives error Mar 17, 2021
@MartinJohns
Copy link
Contributor

MartinJohns commented Mar 17, 2021

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.

@MrNovado
Copy link

MrNovado commented Mar 17, 2021

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

@MartinJohns
Copy link
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.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 17, 2021
@RyanCavanaugh
Copy link
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.

@cevek
Copy link
Author

cevek commented Mar 17, 2021

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

@RyanCavanaugh
Copy link
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.

@jogibear9988
Copy link

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

@typescript-bot
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

6 participants