Created
April 19, 2024 16:15
-
-
Save sylvaindethier/0fc4b31d130231aff7bd32091d2474a7 to your computer and use it in GitHub Desktop.
Refine TypeScript utility
This file contains 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
/** | |
* Refine a Type | |
* @example | |
* ```ts | |
* type Refined = Refine<{ foo: string, bar: unknown[] }, { foo: `${number}` }> | |
* // ^? { foo: `${number}`, bar: unknown[] } | |
* ``` | |
*/ | |
export type Refine<T, P extends Partial<T>> = { | |
[k in keyof T]: T[k] & P[k]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment