Skip to content

Instantly share code, notes, and snippets.

@attitude
Created May 3, 2024 11:10
Show Gist options
  • Save attitude/552308bed39a83e0e69ba5b20c859048 to your computer and use it in GitHub Desktop.
Save attitude/552308bed39a83e0e69ba5b20c859048 to your computer and use it in GitHub Desktop.
Utility that makes sure the rest object is empty (according to Typescript) and all properties are used
type NoExtraKeys<T, U extends PropertyKey> = {
[K in keyof T]: K extends U ? T[K] : never;
};
function tsEmptyRestCheck<
U extends PropertyKey,
T extends Record<PropertyKey, unknown>
>(
_object: NoExtraKeys<T, U>,
..._ignored: Array<U>
): void {
// noop
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment