Microsoft/TypeScript
GitHub ã§èŠãLiteral tested as key of a certain type cannot be used as an index type
Open
#57,109 opened on 2024幎1æ20æ¥
BugDomain: Indexed Access TypesHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
"literal", "extends", "keyof", "cannot be used to index type", "conditional"
ð Version & Regression Information
Versions: ^5.0 (regression)
⯠Playground Link
ð» Code
type T = {
k: symbol,
other: boolean, // another key seems required for the bug to appear
}
// Type '"k"' cannot be used as an index type.(2538)
type C = 'k' extends keyof T ? T['k'] : never; // any
ð Actual behavior
An error is produced in the positive clause of the conditional type. The resulting type is incorrect.
ð Expected behavior
No error.
Additional information about the issue
No response