Created
November 21, 2023 15:18
-
-
Save Saturate/655314270689835a7f0cf90017b929b1 to your computer and use it in GitHub Desktop.
Modify typescript 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
/* | |
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