Description
Bug Report
When performing key remapping in mapped types, any property involving a generic type argument is dropped from the resulting type.
🔎 Search Terms
Mapped types with generic properties
Key remapping with generic properties
Properties with generic type dropped from mapped type with 'as' key remapping
🕗 Version & Regression Information
I first noticed it in 4.9.5
and still exhibited in nightly
(5.1.*
). Tried every version in playground down to 4.1.*
, same behavior.
This is the behavior in every version I tried, and I reviewed the FAQ for entries about Type System Behavior
, Classes
, Generics
.
⏯ Playground Link
Playground link with relevant code
💻 Code
export type FilterNothing<T> = { [P in keyof T as T[P] extends T[P] ? P : P]: T[P] }
class Test<Z> {
foo(args: FilterNothing<{ key: number, value: Z, bar: Date }>) {
const { key, value, bar } = args; // value is missing
}
}
🙁 Actual behavior
value
is omitted from the resulting type, even though all properties P
are emitted. Any property that has a type involving a generic type parameter always gets dropped from the key remapping.
🙂 Expected behavior
value
to be on the resulting type as Z
, since its key would be emitted and type looked up by T[P]
.