You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Checking a generic indexed access against a large union of literal aliases takes 16 s on 7.0.2 (5.9 s on 5.9.3) #65654
The tested TypeScript version is 7.0.2 (also 5.9.3 and 6.0.3). macOS, Apple silicon.
User Goal
The user maintains a TypeScript library that generates types from a Postgres schema, and asked me to narrow down why a small generic helper takes about 13 s to type-check against a large generated schema. The repro keeps the generated shape: one alias per table for its column names, a map from table to alias, and the union of all aliases (about 1,700 names).
Setup and Action
node gen.mjs writes main.ts (about 50 KB) and tsconfig.json. Then run tsc -p . --extendedDiagnostics.
The generated main.ts has 300 aliases like type T0Column = 'id' | 'name' | 'c0' | … | 'c11';, then the 9 lines of the template above.
Expected and Actual Behavior
What actually happened: Check time for this one call, parent(column):
Tables (node gen.mjs <n> 12)
5.9.3
7.0.2
100
2.1 s
4.4 s
200
5.0 s
15.2 s
300
5.9 s
16.1 s
Writing the per-table unions inline in Columns, rather than as named aliases, brings the 300-table case to 0.75 s (5.9.3) and 0.93 s (7.0.2).
A CPU profile of 5.9.3 on an equivalent repro has nearly all of the check time (19.4 of 19.7 s, under the profiler) inside getConstraintOfIndexedAccess, called from structuredTypeRelatedTo, and 19.1 s of it in getUnionType: ColumnFor<T>'s constraint appears to be rebuilt for each member of the target union.
What I expected: a check time close to the inline form's, since ColumnFor<T>'s constraint, Columns[Table], is the same union as Column.
Activity