Skip to content

Instantly share code, notes, and snippets.

@barinbritva
Created March 13, 2023 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barinbritva/ce5cc1f909d44368eb6ba28e597dcf3f to your computer and use it in GitHub Desktop.
Save barinbritva/ce5cc1f909d44368eb6ba28e597dcf3f to your computer and use it in GitHub Desktop.
typesafe objectEntries
// https://stackoverflow.com/a/74891854/3359277
export function typeSafeObjectEntries<
T extends { [key: string | number | symbol]: unknown },
K extends keyof T,
V extends T[K]
>(o: T) {
return Object.entries(o) as unknown as [K, V][];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment