Skip to content

Instantly share code, notes, and snippets.

@Saturate
Created November 21, 2023 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Saturate/655314270689835a7f0cf90017b929b1 to your computer and use it in GitHub Desktop.
Save Saturate/655314270689835a7f0cf90017b929b1 to your computer and use it in GitHub Desktop.
Modify typescript type
/*
Helpful utility type for modifying a interface defined by for example swagger, where we can't edit the type/interface directly.
Let's say that we have the following:
baskets: BasketTypes.ISavedBasket[];
But the ID in `ISavedBasket` can be undefined due to the type, but this is not the real case from the API, just the type
as a basket without id could never exsist.
We can override just the id like this:
baskets: Modify<BasketTypes.ISavedBasket, {
id: string;
}>[];
*/
export type Modify<T, R> = Omit<T, keyof R> & R;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment