Skip to content

Instantly share code, notes, and snippets.

@kaareloun
Last active April 15, 2025 14:52
Show Gist options
  • Save kaareloun/bd8c829d1e497d114827cad20f8b59db to your computer and use it in GitHub Desktop.
Save kaareloun/bd8c829d1e497d114827cad20f8b59db to your computer and use it in GitHub Desktop.
Typescript utilities
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