Skip to content

Instantly share code, notes, and snippets.

@sylvaindethier
Created April 19, 2024 16:15
Show Gist options
  • Save sylvaindethier/0fc4b31d130231aff7bd32091d2474a7 to your computer and use it in GitHub Desktop.
Save sylvaindethier/0fc4b31d130231aff7bd32091d2474a7 to your computer and use it in GitHub Desktop.
Refine TypeScript utility
/**
* 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