Created
May 3, 2024 11:10
-
-
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
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
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