re: Notes on TypeScript: Mapped Types and Lookup Types VIEW POST


Incredible series, thanks so much for sharing this.

Would greatly appreciate if you could clarify the following:

In this example

type RemoveUndefinableKeys<Type> = {
  [Key in keyof Type]: undefined extends Type[Key] ? never : Key

when we pass this portion of a Type

property?: string;

which is the same as

property?: string | undefined

it evaluates to truthy branch of extends, and
I don't quite understand how does it form undefined?

type TestRemoveNullableProperties = {
  property?: undefined;

when supposedly, it should be getting never in true branch.

Another even more confusing thing is if we explicitly

property: string | undefined;

skipping ? marking operator,

we will get

type TestRemoveNullableProperties = {
  property: never;

Thank you.

code of conduct - report abuse