Microsoft/TypeScript
View on GitHubTS2590: Expression produces a union type that is too complex to represent, with simple file using Tuples
Open
#58,268 opened on Apr 21, 2024
Domain: check: Big UnionsHelp WantedPossible Improvement
Repository metrics
- Stars
- (48,455 stars)
- PR merge metrics
- (Avg merge 6d 17h) (9 merged PRs in 30d)
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