Microsoft/TypeScript
Voir sur GitHubLiteral tested as key of a certain type cannot be used as an index type
Open
#57 109 ouverte le 20 janv. 2024
BugDomain: Indexed Access TypesHelp Wanted
Métriques du dépôt
- Stars
- (48 455 stars)
- Métriques de merge PR
- (Merge moyen 6j 17h) (9 PRs mergées en 30 j)
Description
🔎 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