Skip to content

Instantly share code, notes, and snippets.

@babakness
Last active November 25, 2018 01:27
Show Gist options
  • Save babakness/a1ca775f81097ffae04098a8cfdadc60 to your computer and use it in GitHub Desktop.
Save babakness/a1ca775f81097ffae04098a8cfdadc60 to your computer and use it in GitHub Desktop.
A collection of partial types which do not allow for excess properties.
// Inspired by https://stackoverflow.com/users/2887218/jcalz
export type NoExcessStrictPartial<O, P> = {
[K in keyof P]: K extends keyof O ? O[K] : never
}
export type NoExcessDeepPartialValueFlexType<O, P> = {
[K in keyof P]:
K extends keyof O
? NoExcessDeepPartialValueFlexType<O[K],P[K]>
: never
}
export export type NoExcessDeepPartial<O, P> = {
[K in keyof P]:
K extends keyof O
? O[K] extends P[K]
? NoExcessDeepPartial<O[K], P[K]>
: never
: never
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment