-
Notifications
You must be signed in to change notification settings - Fork 12.3k
/
comparisonCountLimits.errors.txt
34 lines (27 loc) · 2.24 KB
/
comparisonCountLimits.errors.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
tests/cases/compiler/comparisonCountLimits.ts(9,17): error TS2590: Expression produces a union type that is too complex to represent.
tests/cases/compiler/comparisonCountLimits.ts(25,1): error TS7062: This source element is ultimately responsible for 1 million type comparisons. It is likely very slow, and may impact editor performance. Simplify the types in use.
==== tests/cases/compiler/comparisonCountLimits.ts (2 errors) ====
function get10BitsOf<T extends string, U extends string, FallbackPrefix extends string>() {
type Bit = T | U; // 2^1
type HalfNibble = `${Bit}${Bit}`; // 2^2
type Nibble = `${HalfNibble}${HalfNibble}`; // 2^4
type Byte = `${Nibble}${Nibble}`; // 2^8
type TenBits = `${Byte}${HalfNibble}`; // 2^10 (approx. 1 million comparisons if compared naively)
type HalfWord = `${Byte}${Byte}`; // 2^16 // allowed, but test takes way too long if used
type Word = `${HalfWord}${HalfWord}`; // 2^32 (throws, too large)
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2590: Expression produces a union type that is too complex to represent.
// Literal type relations are uncached (lol), so everything has to be wrapped in an object to affect cache sizes
// (A distributive conditional is the easiest way to do the mapping, but others are possible, eg, mapped types,
// or explicit construction)
type Box<T> = T extends unknown ? {item: T} : never;
// By manufacturing the fallback in here, we guarantee it has a higher typeid than the bit strings,
// and thus is sorted to the end of the union, guaranteeing relationship checking passes with a maximal
// number of comparisons when a naive comparison is done (guaranteeing this test is slow)
return null as any as Box<TenBits | (FallbackPrefix extends never ? never : `${FallbackPrefix}${string}`)>; // return type is a union
}
let a = get10BitsOf<"0", "1", "a" | "b">();
const b = get10BitsOf<"a", "b", never>();
a = b;
~~~~~~
!!! error TS7062: This source element is ultimately responsible for 1 million type comparisons. It is likely very slow, and may impact editor performance. Simplify the types in use.