Skip to content

Instantly share code, notes, and snippets.

@AlexGeb
Created March 26, 2025 16:46
Show Gist options
  • Save AlexGeb/a01fb925cffb4c0e93ce2244b53547a3 to your computer and use it in GitHub Desktop.
Save AlexGeb/a01fb925cffb4c0e93ce2244b53547a3 to your computer and use it in GitHub Desktop.
hasDefinedKey
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