Microsoft/TypeScript

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

Open

#58,268 建立於 2024年4月21日

在 GitHub 查看
 (7 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
Domain: check: Big UnionsHelp WantedPossible Improvement

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

🔎 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

貢獻者指南