microsoft / microsoft/TypeScript
TS2590: Expression produces a union type that is too complex to represent, with simple file using Tuples
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
TS2590.
There are several issues referring to TS2590, but none with the specific, simple reproduction code below.
🕗 Version & Regression Information
This changed between versions 5.0.0-dev.20221117 and 5.0.0-dev.20221118
⏯ Playground Link
💻 Code
tsc --lib esnext one.ts
one.ts:3:7 - error TS2590: Expression produces a union type that is too complex to represent.
3 const itemCopy: TupleItem = item;
~~~~~~~~
Found 1 error in one.ts:3
// one.ts
import {item, type TupleItem} from './two';
const itemCopy: TupleItem = item;
// two.ts
export declare const item: TupleItem;
export type TupleItem<Tuple = [1], Property = '0'> = {
value: Tuple extends [1] | [2]
? Property extends '0' | 'some' | 'forEach' | 'map' | 'filter' | 'reduce' | 'reduceRight' | 'find' | 'findIndex' | 'fill' | 'copyWithin' | 'entries' | 'keys' | 'values' | 'includes' | 'flatMap' | 'flat' | 'at'
? Property extends keyof Tuple ? Tuple[Property] : undefined
: undefined
: undefined;
};
🙁 Actual behavior
The types fail due to: TS2590: Expression produces a union type that is too complex to represent.
🙂 Expected behavior
The types above are quite simple. Even though the union type has ~20 values, that should not be enough to make the types fail.
Additional information about the issue
Small changes in the code above will fail to reproduce the error, such as:
- Merging both files into a single one
- Not using a
declare constline - Not using generics, or not using generic default types
- Using
Tuple extends ...instead of{value: Tuple extends ...} - Not using
--lib esnext
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the two-file reproduction in one.ts and two.ts, running tsc --lib esnext one.ts and comparing the reported behavior between the two compiler versions named in the issue. Trace the TS2590 diagnostic for the generic TupleItem assignment; done means this minimal reproduction no longer reports the error while preserving the expected type behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100