Created
July 16, 2025 13:34
-
-
Save freddi301/2175fce71632571e3f06b575ab78eb73 to your computer and use it in GitHub Desktop.
Typescript exact type
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 Exact<A, B extends A> = A extends B | |
| ? B | |
| : B extends Record<any, any> | |
| ? { [K in keyof B]: K extends keyof A ? Exact<A[K], B[K]> : never } | |
| : B extends Array<any> | |
| ? { [K in keyof B]: K extends keyof A ? Exact<A[K], B[K]> : never } | |
| : never; | |
| function invariantize<A, R>( | |
| fun: (a: A) => R | |
| ): <B extends A>(a: Exact<A, B>) => R { | |
| return fun as any; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment