Skip to content

Instantly share code, notes, and snippets.

@aiya000
Created November 30, 2020 10:29
Show Gist options
  • Save aiya000/42748c9a53f6ca68217a9dcf7ed3664f to your computer and use it in GitHub Desktop.
Save aiya000/42748c9a53f6ca68217a9dcf7ed3664f to your computer and use it in GitHub Desktop.
/**
* Exposes type utility functions.
* @packageDocumentation
*/
/**
* Does `x` have an undefined property `prop`,
* or that property is `PropType`?
*/
export function haveUndefienedPropertyOrThat<
PropType,
Base,
Prop extends keyof Base
>(p: (a: unknown) => a is PropType, x: Base, prop: Prop): boolean {
const xa = (x as {[P in Prop]?: unknown})[prop]
return xa === undefined || p(xa)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment