Microsoft/TypeScript
Vedi su GitHubwrong behavior about type parameters of `as` clause in a mapped type
Open
#59.713 aperta il 22 ago 2024
Domain: Mapped TypesHelp WantedPossible Improvement
Metriche repository
- Star
- (48.455 star)
- Metriche merge PR
- (Merge medio 6g 17h) (9 PR mergiate in 30 g)
Descrizione
🔎 Search Terms
type parameter as mapped type
🕗 Version & Regression Information
5.7.0-dev.20240821
⏯ Playground Link
💻 Code
type IsString<T> = T[] extends string[] ? true : false
type OmitStringKey<T extends object> = {
[K in keyof T as IsString<T[K]> extends true ? never: K]: T[K]
}
function f<T>(t: T): { data: T } {
type A = IsString<T> // deferred
type B = A extends true ? true : false // deferred
type C = IsString<{data: T}['data']> // deferred
return {} as OmitStringKey<{ data: T }> // `data` is omitted
}
🙁 Actual behavior
OmitStringKey<{ data: T }> omit data property. That means IsString<T> extends true in the as clause is true, while T is not decided yet.
🙂 Expected behavior
type evaluation should be deferred
Additional information about the issue
No response