-
-
Save vendethiel/e9ea474749289da4fb4bd39be131715a to your computer and use it in GitHub Desktop.
hasDefinedKey
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
export const hasDefinedKey = | |
<K extends PropertyKey>(key: K) => | |
<T extends Partial<Record<K, unknown>>>( | |
obj: T, | |
): obj is T & Record<K, Exclude<T[K], undefined>> => | |
key in obj && obj[key] !== undefined; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment