loading...

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

FULL DISCUSSION
 

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
pass

property: string | undefined;

skipping ? marking operator,

we will get

type TestRemoveNullableProperties = {
  ...
  property: never;
}

Thank you.

code of conduct - report abuse