-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
TS2590: Expression produces a union type that is too complex to represent, with simple file using Tuples #58268
Comments
Even with everything in one file, this code just doesn't seem to work at all:
|
Thanks for looking into this @fatcerberus. That's a different error. This one can be fixed by using this instead: 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;
}; That failure is expected and relates to whether The bug above instead relates to TypeScript creating a big union type, which makes type checking crash, which is different. To be able to reproduce it, it seems like 2 separate files (exactly identical to the above) must be used. |
The code as written in the OP produces that error, including when split into two files. That's confusing since it's not the error message you're reporting and makes it look like the repro itself is erroneous. For what it's worth I wasn't able to reproduce the too-large-union-type error using the bug workbench (which, unlike the playground, does support multiple files): |
I have updated the original issue to reflect this, and avoid the confusion with that other unrelated error.
Oh I did not know the Bug Workbench supported multiple files. You could not reproduce the bug because it requires using The following is a reproduction of the bug using the Bug Workbench. That link works. However, interestingly enough, if you click on the URL (which adds |
Quick notes The stack looks like this We're testing if
To do this we compute the variance of
Then we go down the structural comparison on
This eventually hits the limiting case
because
I believe the definitions in |
Not really sure this is going to be "fixable". What's the desired behavior of |
π 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
and5.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
π 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:
declare const
lineTuple extends ...
instead of{value: Tuple extends ...}
--lib esnext
The text was updated successfully, but these errors were encountered: