Skip to content

TS v4: Array#every throws on compilation for unions of arrays #49435

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
nicolas377 opened this issue Jun 8, 2022 · 2 comments
Closed

TS v4: Array#every throws on compilation for unions of arrays #49435

nicolas377 opened this issue Jun 8, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@nicolas377
Copy link
Contributor

nicolas377 commented Jun 8, 2022

πŸ”Ž Search Terms

.every, ReadonlyArray#every, array.every

πŸ•— Version & Regression Information

  • This changed between versions 3.9.7 and 4.0.5

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare const someArray:
  | ["eslint:recommended", "plugin:import/recommended", "prettier"]
  | ["plugin:@typescript-eslint/recommended", "plugin:import/typescript"]
  | ["plugin:react/recommended"];

someArray.every((val: unknown) => typeof val === "string");

πŸ™ Actual behavior

TS(2349), because the signatures of the possible someArray.every calls conflict with each other.

πŸ™‚ Expected behavior

The someArray.every call should compile for all possible values of someArray.

Notes from the issue author

This is similar to #40157, but that issue uses a union of an array and 2D array.
Could be similar to #40217, but the error there was marked in a function call inside of the .every callback.
This issue is also reproducible using ReadonlyArray, see the playground for that.

@jcalz
Copy link
Contributor

jcalz commented Jun 8, 2022

I'd say this is a duplicate of #44373

Of course it's also a duplicate of #40157, they are both unions of arrays with uncallable methods.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 8, 2022
@RyanCavanaugh
Copy link
Member

The someArray.every call should compile for all possible values of someArray.

Note that we very much intentionally do not things which are combinatorially explosive

@RyanCavanaugh RyanCavanaugh closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2022
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

3 participants