Skip to content

Fixed an issue with apparent mapped type keys - #57838

Closed
Mateusz Burzyński (Andarist) wants to merge 10 commits into
microsoft:mainfrom
Andarist:fix/apparent-mapped-type-keys-with-unknown-modifier
Closed

Fixed an issue with apparent mapped type keys#57838
Mateusz Burzyński (Andarist) wants to merge 10 commits into
microsoft:mainfrom
Andarist:fix/apparent-mapped-type-keys-with-unknown-modifier

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

fixes#57827

Comment threadsrc/compiler/checker.ts Outdated
t => void mappedKeys.push(instantiateType(nameType, appendTypeMapping(targetType.mapper, getTypeParameterFromMappedType(targetType), t))),
);
return getUnionType(mappedKeys);
return mappedKeys.length ? getUnionType(mappedKeys) : stringNumberSymbolType;

@AndaristMateusz Burzyński (Andarist)Mar 18, 2024

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that when modifiersType is unknown (or {}) then keyof modifiersType is never. Since never is assignable to everything, the checker assumed that keyof { [P in keyof T as T[P] extends string ? P: never]: any } is assignable to string.

Then based on that information it managed to simplify the instantiated substitution type of Extract to just keyof { [P in keyof T as T[P] extends string ? P: never]: any } (its newBaseType). Then in turn getNarrowableTypeForReference concluded that it should substitute constraints. Those were substituted with stringNumberSymbolType (for the keyof ...) and that's not assignable to string.

Before #56742 , it didn't mistakenly assume that keyof { [P in keyof T as T[P] extends string ? P: never]: any } is assignable to string so the substitution type was instantiated as (keyof { [P in keyof T as T[P] extends string ? P: never]: any }) & string and that is assignable to a string.

@LukeAbby

Copy link
Copy Markdown

Hi! I appreciate that reviewers can be very busy but I discovered this PR when bisecting my own issue with a bit of an absurd reproduction that was erroring with a much more opaque error "Type instantiation is excessively deep and possibly infinite." so I was unable to find any workarounds before the process of bisecting.

I'd really like to see this PR merged because when I built it locally it makes my code work! I wouldn't want to ask this of anyone else without being willing to do it myself so I did also review it and I can't find anything objectionable, though of course my opinion doesn't weigh as much given I'm not a maintainer.

@gabritto

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) pack this

@typescript-bot

TypeScript Bot (typescript-bot) commented Nov 30, 2024

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

CommandStatusResults
pack this✅ Started✅ Results

@typescript-bot

TypeScript Bot (typescript-bot) commented Nov 30, 2024

Copy link
Copy Markdown
Contributor

Hey Gabriela Araujo Britto (@gabritto), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
"devDependencies": {
"typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/164242/artifacts?artifactName=tgz&fileId=63DB465238EF48184C9FE24AA2B166C04B5AAA3CA7F9AFB4F3F63BF467E24E8402&fileName=/typescript-5.8.0-insiders.20241130.tgz"
}
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.8.0-pr-57838-3".;

@gabritto

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) test it

@typescript-bot

TypeScript Bot (typescript-bot) commented Nov 30, 2024

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

CommandStatusResults
test top400✅ Started✅ Results
user test this✅ Started✅ Results
run dt✅ Started✅ Results
perf test this faster✅ Started👀 Results

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto) Here are the results of running the user tests with tsc comparing main and refs/pull/57838/merge:

Everything looks good!

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Gabriela Araujo Britto (@gabritto), the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto)
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-Unions - node (v18.15.0, x64)
Errors3434~~~p=1.000 n=6
Symbols62,36362,363~~~p=1.000 n=6
Types50,39550,395~~~p=1.000 n=6
Memory used194,857k (± 1.02%)194,229k (± 0.95%)~193,006k196,645kp=0.173 n=6
Parse Time1.30s (± 0.75%)1.31s (± 0.89%)~1.29s1.32sp=0.109 n=6
Bind Time0.72s0.72s~~~p=1.000 n=6
Check Time9.81s (± 0.28%)9.81s (± 0.51%)~9.71s9.85sp=0.809 n=6
Emit Time2.74s (± 0.64%)2.72s (± 0.23%)~2.71s2.73sp=0.070 n=6
Total Time14.57s (± 0.11%)14.56s (± 0.38%)~14.45s14.60sp=1.000 n=6
angular-1 - node (v18.15.0, x64)
Errors3737~~~p=1.000 n=6
Symbols947,936947,936~~~p=1.000 n=6
Types410,955410,955~~~p=1.000 n=6
Memory used1,226,005k (± 0.00%)1,226,007k (± 0.00%)~1,225,969k1,226,073kp=0.936 n=6
Parse Time6.65s (± 0.64%)6.65s (± 0.46%)~6.61s6.70sp=1.000 n=6
Bind Time1.89s (± 0.33%)1.89s (± 0.27%)~1.88s1.89sp=0.386 n=6
Check Time31.96s (± 0.24%)31.95s (± 0.39%)~31.73s32.06sp=0.810 n=6
Emit Time15.22s (± 0.51%)15.20s (± 0.51%)~15.11s15.33sp=0.688 n=6
Total Time55.72s (± 0.14%)55.69s (± 0.22%)~55.55s55.84sp=0.688 n=6
mui-docs - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols2,501,4642,501,464~~~p=1.000 n=6
Types909,569909,569~~~p=1.000 n=6
Memory used2,318,592k (± 0.00%)2,318,551k (± 0.00%)~2,318,489k2,318,648kp=0.230 n=6
Parse Time9.29s (± 0.32%)9.28s (± 0.24%)~9.25s9.32sp=0.681 n=6
Bind Time2.18s (± 0.69%)2.16s (± 0.63%)-0.02s (- 0.92%)2.14s2.18sp=0.040 n=6
Check Time74.81s (± 0.54%)75.28s (± 0.61%)~74.90s76.10sp=0.173 n=6
Emit Time0.29s (± 3.60%)0.29s (± 2.61%)~0.28s0.30sp=0.931 n=6
Total Time86.56s (± 0.46%)87.01s (± 0.53%)~86.63s87.84sp=0.229 n=6
self-build-src - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,225,2511,225,251~~~p=1.000 n=6
Types266,546266,546~~~p=1.000 n=6
Memory used2,354,384k (± 0.01%)2,414,937k (± 6.12%)~2,353,863k2,717,160kp=1.000 n=6
Parse Time5.26s (± 0.79%)5.21s (± 1.14%)~5.16s5.33sp=0.066 n=6
Bind Time1.80s (± 0.58%)1.78s (± 1.23%)~1.74s1.80sp=0.210 n=6
Check Time35.20s (± 0.20%)35.16s (± 0.41%)~34.96s35.36sp=0.575 n=6
Emit Time2.98s (± 1.57%)2.97s (± 2.65%)~2.82s3.04sp=1.000 n=6
Total Time45.25s (± 0.24%)45.14s (± 0.38%)~44.87s45.31sp=0.296 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,225,2511,225,251~~~p=1.000 n=6
Types266,546266,546~~~p=1.000 n=6
Memory used2,786,942k (±14.25%)2,907,388k (±12.89%)~2,422,757k3,149,947kp=0.936 n=6
Parse Time6.91s (± 2.11%)6.99s (± 1.69%)~6.82s7.11sp=0.261 n=6
Bind Time2.18s (± 1.12%)2.15s (± 2.23%)~2.10s2.22sp=0.470 n=6
Check Time42.86s (± 0.64%)42.81s (± 0.45%)~42.46s43.03sp=0.378 n=6
Emit Time3.51s (± 4.08%)3.54s (± 2.34%)~3.45s3.66sp=0.810 n=6
Total Time55.46s (± 0.67%)55.50s (± 0.29%)~55.18s55.61sp=0.810 n=6
self-compiler - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols262,223262,223~~~p=1.000 n=6
Types106,607106,607~~~p=1.000 n=6
Memory used439,759k (± 0.01%)439,832k (± 0.02%)~439,755k439,988kp=0.092 n=6
Parse Time3.56s (± 0.92%)3.57s (± 0.62%)~3.54s3.60sp=0.418 n=6
Bind Time1.32s (± 1.27%)1.32s (± 1.24%)~1.30s1.34sp=0.742 n=6
Check Time18.96s (± 0.42%)18.98s (± 0.35%)~18.88s19.07sp=0.810 n=6
Emit Time1.53s (± 0.99%)1.54s (± 0.76%)~1.53s1.56sp=0.071 n=6
Total Time25.36s (± 0.32%)25.42s (± 0.34%)~25.32s25.54sp=0.260 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors7070~~~p=1.000 n=6
Symbols226,062226,062~~~p=1.000 n=6
Types94,48894,488~~~p=1.000 n=6
Memory used371,703k (± 0.07%)371,545k (± 0.01%)-158k (- 0.04%)371,497k371,567kp=0.005 n=6
Parse Time2.90s (± 1.38%)2.87s (± 1.48%)~2.81s2.93sp=0.258 n=6
Bind Time1.58s (± 1.31%)1.59s (± 1.08%)~1.57s1.62sp=0.288 n=6
Check Time16.46s (± 0.46%)16.46s (± 0.24%)~16.41s16.50sp=0.936 n=6
Emit Time0.00s0.00s (±244.70%)~0.00s0.01sp=0.405 n=6
Total Time20.93s (± 0.52%)20.92s (± 0.30%)~20.82s20.97sp=0.936 n=6
vscode - node (v18.15.0, x64)
Errors44~~~p=1.000 n=6
Symbols3,188,2263,188,226~~~p=1.000 n=6
Types1,096,5661,096,566~~~p=1.000 n=6
Memory used3,262,606k (± 0.02%)3,262,564k (± 0.01%)~3,262,003k3,263,113kp=0.936 n=6
Parse Time14.12s (± 0.49%)14.16s (± 0.58%)~14.08s14.30sp=0.226 n=6
Bind Time4.56s (± 2.12%)4.57s (± 1.87%)~4.52s4.74sp=0.462 n=6
Check Time87.52s (± 1.53%)87.41s (± 2.21%)~85.83s89.91sp=0.575 n=6
Emit Time28.05s (± 3.03%)27.31s (± 7.94%)~23.07s28.89sp=0.936 n=6
Total Time134.24s (± 0.83%)133.44s (± 1.09%)~131.81s135.89sp=0.230 n=6
webpack - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols288,733288,733~~~p=1.000 n=6
Types117,152117,152~~~p=1.000 n=6
Memory used441,046k (± 0.03%)440,980k (± 0.03%)~440,825k441,235kp=0.471 n=6
Parse Time4.08s (± 0.59%)4.09s (± 0.51%)~4.06s4.12sp=0.375 n=6
Bind Time1.73s (± 0.87%)1.75s (± 1.02%)~1.73s1.78sp=0.164 n=6
Check Time18.86s (± 0.33%)18.88s (± 0.58%)~18.75s19.01sp=0.936 n=6
Emit Time0.00s (±244.70%)0.00s~~~p=0.405 n=6
Total Time24.68s (± 0.34%)24.73s (± 0.39%)~24.60s24.84sp=0.261 n=6
xstate-main - node (v18.15.0, x64)
Errors55~~~p=1.000 n=6
Symbols552,390552,390~~~p=1.000 n=6
Types185,096185,096~~~p=1.000 n=6
Memory used492,477k (± 0.02%)492,467k (± 0.01%)~492,390k492,517kp=0.575 n=6
Parse Time3.41s (± 1.28%)3.41s (± 0.79%)~3.37s3.45sp=0.746 n=6
Bind Time1.17s (± 1.00%)1.18s (± 0.93%)~1.17s1.20sp=0.383 n=6
Check Time19.59s (± 1.48%)19.43s (± 0.40%)~19.33s19.56sp=0.296 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time24.18s (± 1.32%)24.03s (± 0.36%)~23.93s24.16sp=0.376 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

Comment threadtests/cases/compiler/keyRemappingKeyofResult.ts
Comment threadsrc/compiler/checker.ts Outdated
@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto) Here are the results of running the top 400 repos with tsc comparing main and refs/pull/57838/merge:

Everything looks good!

@Andarist
Mateusz Burzyński (Andarist)force-pushed the fix/apparent-mapped-type-keys-with-unknown-modifier branch from 2f2b500 to cad532aCompareNovember 30, 2024 15:45
Comment threadsrc/compiler/checker.ts Outdated
@Andarist
Mateusz Burzyński (Andarist)force-pushed the fix/apparent-mapped-type-keys-with-unknown-modifier branch from cf0355f to 21f4f7cCompareJanuary 20, 2026 19:40
@gabritto

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) test it

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

CommandStatusResults
test top400✅ Started✅ Results
user test this✅ Started✅ Results
run dt✅ Started✅ Results
perf test this faster✅ Started👀 Results

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Gabriela Araujo Britto (@gabritto), the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto) Here are the results of running the user tests with tsc comparing main and refs/pull/57838/merge:

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Package install failed"
  • 1 instance of "Git clone failed"

Otherwise...

Everything looks good!

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto)
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-Unions - node (v18.15.0, x64)
Errors22~~~p=1.000 n=6
Symbols62,37062,370~~~p=1.000 n=6
Types50,38750,387~~~p=1.000 n=6
Memory used194,389k (± 1.03%)193,173k (± 0.80%)~192,520k196,349kp=0.173 n=6
Parse Time1.30s (± 0.76%)1.30s (± 0.75%)~1.29s1.32sp=0.924 n=6
Bind Time0.76s0.76s~~~p=1.000 n=6
Check Time9.90s (± 0.40%)9.85s (± 0.17%)-0.05s (- 0.54%)9.82s9.87sp=0.043 n=6
Emit Time2.73s (± 0.40%)2.73s (± 0.44%)~2.72s2.75sp=0.666 n=6
Total Time14.69s (± 0.31%)14.65s (± 0.20%)~14.61s14.69sp=0.077 n=6
angular-1 - node (v18.15.0, x64)
Errors22~~~p=1.000 n=6
Symbols955,823955,823~~~p=1.000 n=6
Types415,853415,853~~~p=1.000 n=6
Memory used1,253,913k (± 0.01%)1,253,962k (± 0.00%)~1,253,896k1,254,007kp=0.173 n=6
Parse Time6.55s (± 0.59%)6.51s (± 0.60%)~6.47s6.58sp=0.147 n=6
Bind Time1.96s (± 0.26%)1.95s (± 0.28%)~1.95s1.96sp=0.640 n=6
Check Time32.38s (± 0.36%)32.40s (± 0.34%)~32.28s32.56sp=1.000 n=6
Emit Time15.03s (± 0.28%)15.01s (± 0.27%)~14.94s15.05sp=0.377 n=6
Total Time55.92s (± 0.25%)55.88s (± 0.24%)~55.73s56.09sp=0.378 n=6
mui-docs - node (v18.15.0, x64)
Errors11,43911,439~~~p=1.000 n=6
Symbols2,700,2372,700,237~~~p=1.000 n=6
Types930,441930,441~~~p=1.000 n=6
Memory used3,036,188k (± 0.00%)3,036,138k (± 0.00%)~3,036,042k3,036,274kp=0.423 n=6
Parse Time8.58s (± 0.14%)8.58s (± 0.32%)~8.55s8.63sp=0.742 n=6
Bind Time2.30s2.30s (± 0.35%)~2.29s2.31sp=0.290 n=6
Check Time92.83s (± 0.33%)92.79s (± 0.91%)~91.08s93.28sp=0.298 n=6
Emit Time0.31s (± 2.60%)0.32s (± 1.63%)~0.31s0.32sp=0.523 n=6
Total Time104.02s (± 0.29%)103.99s (± 0.82%)~102.26s104.44sp=0.297 n=6
self-build-src - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,252,4441,252,446+2 (+ 0.00%)~~p=0.001 n=6
Types259,946259,946~~~p=1.000 n=6
Memory used2,448,166k (± 6.06%)2,448,668k (± 6.06%)~2,387,309k2,751,714kp=0.378 n=6
Parse Time5.18s (± 0.57%)5.14s (± 0.95%)~5.07s5.22sp=0.077 n=6
Bind Time1.86s (± 0.81%)1.86s (± 0.63%)~1.85s1.88sp=0.621 n=6
Check Time35.38s (± 0.55%)35.38s (± 0.41%)~35.12s35.52sp=0.936 n=6
Emit Time3.04s (± 1.52%)2.97s (± 1.36%)-0.07s (- 2.30%)2.92s3.03sp=0.030 n=6
Total Time45.46s (± 0.30%)45.38s (± 0.26%)~45.23s45.52sp=0.298 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,252,4441,252,446+2 (+ 0.00%)~~p=0.001 n=6
Types259,946259,946~~~p=1.000 n=6
Memory used3,183,385k (± 0.03%)3,062,085k (± 9.66%)~2,457,737k3,183,539kp=0.230 n=6
Parse Time6.79s (± 0.58%)6.77s (± 1.33%)~6.61s6.88sp=0.810 n=6
Bind Time2.27s (± 1.45%)2.26s (± 1.62%)~2.21s2.31sp=0.872 n=6
Check Time43.22s (± 0.26%)43.06s (± 0.63%)~42.57s43.31sp=0.471 n=6
Emit Time3.49s (± 1.81%)3.47s (± 2.15%)~3.34s3.55sp=0.810 n=6
Total Time55.77s (± 0.31%)55.56s (± 0.65%)~54.92s55.93sp=0.298 n=6
self-compiler - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols264,690264,692+2 (+ 0.00%)~~p=0.001 n=6
Types104,079104,079~~~p=1.000 n=6
Memory used443,095k (± 0.01%)443,077k (± 0.03%)~442,845k443,232kp=0.936 n=6
Parse Time3.52s (± 1.41%)3.53s (± 0.94%)~3.49s3.58sp=0.747 n=6
Bind Time1.38s (± 1.33%)1.38s (± 0.92%)~1.37s1.40sp=1.000 n=6
Check Time19.08s (± 0.37%)19.22s (± 0.37%)+0.14s (+ 0.71%)19.09s19.29sp=0.013 n=6
Emit Time1.53s (± 1.73%)1.54s (± 1.57%)~1.51s1.57sp=0.625 n=6
Total Time25.52s (± 0.30%)25.67s (± 0.41%)+0.15s (+ 0.60%)25.48s25.78sp=0.045 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors7373~~~p=1.000 n=6
Symbols225,493225,493~~~p=1.000 n=6
Types94,37394,373~~~p=1.000 n=6
Memory used369,855k (± 0.02%)369,872k (± 0.04%)~369,732k370,161kp=0.936 n=6
Parse Time2.81s (± 1.04%)2.80s (± 0.63%)~2.78s2.83sp=0.371 n=6
Bind Time1.64s (± 0.81%)1.64s (± 1.18%)~1.62s1.67sp=0.934 n=6
Check Time16.59s (± 0.20%)16.60s (± 0.53%)~16.51s16.73sp=1.000 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time21.05s (± 0.22%)21.05s (± 0.41%)~20.95s21.18sp=0.872 n=6
vscode - node (v18.15.0, x64)
Errors1111~~~p=1.000 n=6
Symbols4,136,5314,136,531~~~p=1.000 n=6
Types1,309,9571,309,957~~~p=1.000 n=6
Memory used3,932,744k (± 0.00%)3,932,730k (± 0.00%)~3,932,553k3,932,940kp=0.810 n=6
Parse Time16.02s (± 1.00%)16.05s (± 0.67%)~15.92s16.19sp=0.689 n=6
Bind Time5.54s (± 2.69%)5.67s (± 0.38%)~5.64s5.69sp=0.223 n=6
Check Time115.50s (± 2.45%)114.17s (± 2.01%)~112.14s118.32sp=0.378 n=6
Emit Time47.17s (±17.07%)47.36s (±18.97%)~39.33s57.85sp=0.810 n=6
Total Time184.24s (± 5.35%)183.25s (± 5.75%)~173.13s193.96sp=0.689 n=6
webpack - node (v18.15.0, x64)
Errors4141~~~p=1.000 n=6
Symbols383,981383,981~~~p=1.000 n=6
Types167,978167,978~~~p=1.000 n=6
Memory used543,784k (± 0.02%)543,718k (± 0.03%)~543,545k544,045kp=0.471 n=6
Parse Time4.63s (± 0.26%)4.63s (± 0.59%)~4.60s4.68sp=0.684 n=6
Bind Time2.02s (± 1.14%)2.04s (± 1.02%)~2.00s2.06sp=0.331 n=6
Check Time23.66s (± 1.45%)23.67s (± 1.64%)~23.13s23.97sp=1.000 n=6
Emit Time0.00s (±244.70%)0.00s~~~p=0.405 n=6
Total Time30.31s (± 1.14%)30.34s (± 1.31%)~29.80s30.64sp=0.688 n=6
xstate-main - node (v18.15.0, x64)
Errors3030~~~p=1.000 n=6
Symbols729,756729,721-35 (- 0.00%)~~p=0.001 n=6
Types218,510218,479-31 (- 0.01%)~~p=0.001 n=6
Memory used633,780k (± 0.01%)633,742k (± 0.01%)~633,662k633,834kp=0.575 n=6
Parse Time4.56s (± 0.43%)4.57s (± 0.55%)~4.53s4.60sp=0.622 n=6
Bind Time1.47s (± 0.90%)1.48s (± 0.92%)~1.47s1.51sp=0.068 n=6
Check Time22.01s (± 0.52%)22.05s (± 0.34%)~21.98s22.17sp=0.518 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time28.05s (± 0.46%)28.10s (± 0.32%)~27.98s28.23sp=0.422 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto) Here are the results of running the top 400 repos with tsc comparing main and refs/pull/57838/merge:

Everything looks good!

Comment threadsrc/compiler/checker.ts Outdated
);
return getUnionType(mappedKeys);
const apparentKeys = getUnionType(mappedKeys);
if (forSource && apparentKeys.flags & TypeFlags.Never) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I wasn't completely clear, I think moving this check to this function allows us to simply check if modifiersType is unknown, and then we return string | number | symbol instead of never. To me this would make more clear where the special case is coming from and when it should be applied. But maybe this should actually be applied whenever never is there result, regardless of what the modifiers type was? That's what I'm confused about still.

What I also find confusing about the existing use of getApparentMappedTypeKeys is that, if we're using it to compare a source type with a target type, I would imagine we want to be conservative and obtain the largest possible type the source type could be. But the logic of getApparentMappedTypeKeys seems to compute the smallest possible type the source type could be: if we have some generic mapped type M, its apparent type will be, say, M1, and M <: M1 (M``` is a subtype of M1). We then compute the keyof M1, but I think keyofis contravariant, and sokeyof M :> keyof M1, so we're effectively approximating keyof M by a subtype of it, whereas to be conservative on the side of a source type, we'd need to approximate keyof M by a supertype. Wesley Wigham (@weswigham) is my thinking wrong here?

If that all made sense, then this PR fixes the keyof approximation by inverting never (smallest type for a key) and string | number | symbol (largest type for a key), but then I still worry the cases in between could be wrong.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You raise a good point here, I'll research this further and come back with some thoughts

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's wrong:

typeAcceptString<Textendsstring>=T;typeFilterByLiteralValue<T,V>={[PinkeyofTasT[P]extendsV ? P : never]: any};functiontest<Textends{a: 1;b: 2}>(k: keyofFilterByLiteralValue<T,1>){consts: string=k;// errors correctlytypeResult=AcceptString<typeofk>// doesn't error but it should}

So yes, you are right - obtaining apparent keys on the source side isn't the right approach at all.

@Andarist
Mateusz Burzyński (Andarist) marked this pull request as draft February 9, 2026 10:32
@Andarist
Mateusz Burzyński (Andarist)force-pushed the fix/apparent-mapped-type-keys-with-unknown-modifier branch from 7c57147 to 73d96e1CompareFebruary 9, 2026 13:10
@github-project-automationgithub-project-automationBot moved this from Waiting on reviewers to Done in PR BacklogMar 24, 2026
@typescript-bot

Copy link
Copy Markdown
Contributor

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Extract not narrowing type union in mapped type passed as generic

7 participants

@Andarist@LukeAbby@gabritto@typescript-bot@sandersn@weswigham@RyanCavanaugh