gcanti / typelevel-ts

Type level programming in TypeScript
https://gcanti.github.io/typelevel-ts
MIT License
357 stars 12 forks source link

Fix RequiredKeys and OptionalKeys #36

Closed stefanobaghino closed 6 years ago

stefanobaghino commented 6 years ago

Introduces a simple fix that allows the compiler to more easily recognize that both RequiredKeys and OptionalKeys for some type A are assignable to keyof A. This fix allows, for example, to easily define a generic type that contains all required keys of another:

type RequiredPart<A extends object> = Pick<A, RequiredKeys<A>>

Before this fix, the user would have had to give a further hint to the compiler by specifying the second type parameters of Pick in the example above as an intersection between RequiredKeys<A> and keyof<A> to obtain the same effect.

gcanti commented 6 years ago

Going to close this, thanks @stefanobaghino for this PR and @ajafff for reviewing