loading...

re: Notes on TypeScript: Conditional Types VIEW POST

FULL DISCUSSION
 

Thanks for the writeup! There are two spots where I got stuck and I think they are related.

1.

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

2.

type GetPropertyTypes<Type> = Type extends {a: infer U, b: infer U} ? U : never;

In 1. I got confused by the [keyof Type] at the end of the expression; how does it work?

In 2. I got confused by having the same type variable U used twice in different spots returning different values.

There is some form of relationship-forming happening where I can‘t follow because I don‘t know how the compiler works out a solution. Could you expand a bit on this and maybe show step by step how the compiler arrives at a solution? Now that I think of this I believe that understanding this is fundamental to getting how the whole type system works 🤔

 

Thanks for the feedback!
Will try to update the post with further explanations.

code of conduct - report abuse