Microsoft/TypeScript

TS2590: Expression produces a union type that is too complex to represent, with simple file using Tuples

Open

#58.268 geöffnet am 21. Apr. 2024

Auf GitHub ansehen
 (7 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
Domain: check: Big UnionsHelp WantedPossible Improvement

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

🔎 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

https://www.typescriptlang.org/dev/bug-workbench/?ssl=2&ssc=16&pln=2&pc=1#code/PTAEAEDMEsBsFMB2BDAtvAXKA9o+A6AFwGcBYAKBAlmgCMt5i8APQi6VAB2wCdDQA3tELxUAGlCEAnp3igAKgFdOCAJIjUAX1CQe2VKADk+YIQDu2QwG4KFAMa5i-YaIDC2TlKxKV8daNAAXlAXVBtyCiooOCQ0TEkLIjJyeGZuPlAAE3g7WGQeOQdEJxCNb2U1DXCKVPT+aVkFCr8NAB4fBCDQAG0ARgBdCQAFPVk+KS7DAAZDAD4ugQoASAA3ZFhFeI65VJFETOIegdAAHx6AJn7lpYB+UBGPeHHQXaQDoxnTo2J9eEMvwyQXgAUWQdgAFv8zoZUMhOFCjDBYCIeAjDAVMoo7H8ARisfAAErQADm4MIaJg+wp0H2qn2qWpsFgaIcngA6sJwTS0UhCDxoIw0QBreBSYhotYbQUAmm5RTZcUAyB5QgAWThFJVaOQ5Out3uoye0herDehxFUmwkCavlAd223QeY2k-VAWEU9Mp8Eyevdnpp3uufuyXsy4U0ViAA

💻 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 const line
  • Not using generics, or not using generic default types
  • Using Tuple extends ... instead of {value: Tuple extends ...}
  • Not using --lib esnext

Contributor Guide