Last active
April 15, 2025 14:52
-
-
Save kaareloun/bd8c829d1e497d114827cad20f8b59db to your computer and use it in GitHub Desktop.
Typescript utilities
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
import "@total-typescript/ts-reset"; | |
export {} | |
// Makes all properties optional | |
export type DeepPartial<T> = T extends object | |
? { | |
[P in keyof T]?: DeepPartial<T[P]> | |
} | |
: T | |
// Exclusive or, use instead of ({ a: 'a' } | { b: 'b' }) & { c: 'c' } | |
export type XOR<T, U> = | |
| (T & { [K in Exclude<keyof U, keyof T>]?: never }) | |
| (U & { [K in Exclude<keyof T, keyof U>]?: never }) | |
// Make chosen fields required | |
export type WithRequired<TType, TRequiredKeys extends keyof TType> = TType & { | |
[P in TRequiredKeys]-?: TType[P] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment