Created
November 30, 2020 10:29
-
-
Save aiya000/42748c9a53f6ca68217a9dcf7ed3664f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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