Created
February 9, 2026 23:19
-
-
Save graffhyrum/d5ce2e26484acd7547d7a3671aa64d88 to your computer and use it in GitHub Desktop.
The `Modify` type is a utility type that creates a modified version of a given base type by omitting certain properties and making others optional.
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
| declare const brand: unique symbol; | |
| export type Brand<BaseType, TBrand extends PropertyKey> = BaseType & { [brand]: TBrand }; | |
| /** | |
| * The `Modify` type is a utility type that creates a modified version of a given base type | |
| * by omitting certain properties and making others optional. This is composed of three main | |
| * operations: | |
| * | |
| * - Removes properties from the base type as specified in the `Omitted` parameter. | |
| * - Makes properties optional as specified in the `Optional` parameter from the remaining keys | |
| * after omission. | |
| * - Retains other properties without modification. | |
| * | |
| * @template BaseType The original base type from which modifications are made. This should be an object type. | |
| * @template Omitted The union of keys in the base type to be omitted entirely. | |
| * @template Optional The union of keys in the base type, after omission, to be marked as optional. | |
| */ | |
| export type Modify< | |
| BaseType extends object, | |
| Omitted extends PropertyKey & keyof BaseType = never, | |
| Optional extends PropertyKey & keyof Omit<BaseType, Omitted> = never, | |
| > = Omit<Omit<BaseType, Omitted>, Optional> & Partial<Pick<BaseType, Optional>>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment