Created
March 26, 2025 16:46
-
-
Save AlexGeb/a01fb925cffb4c0e93ce2244b53547a3 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