Skip to content

Instantly share code, notes, and snippets.

@barinbritva
Created March 13, 2023 12:24
Show Gist options
  • 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