Skip to content

Instantly share code, notes, and snippets.

@aiya000
Created November 30, 2020 04:47
Show Gist options
  • Save aiya000/e4b876b8f07128396c7e82c0ffcbf246 to your computer and use it in GitHub Desktop.
Save aiya000/e4b876b8f07128396c7e82c0ffcbf246 to your computer and use it in GitHub Desktop.
function hasUndefienedPropertyOrThat<
PropType,
Prop extends string,
Base extends { [P in Prop]?: PropType }
>(p: (x: PropType | undefined) => x is PropType, x: Base, prop: Prop): boolean {
return x[prop] === undefined || p(x[prop]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment