Skip to content

Commit

Permalink
feat(ObjectUtils): Add Partialise
Browse files Browse the repository at this point in the history
**Partialise<T, Keys>**:
  Makes given keys of T optional undiscriminately.
  If no keys are given, makes all keys partial.
  • Loading branch information
SirWrexes committed Sep 18, 2023
1 parent 42d3a6e commit 07160ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/OjectUtils.test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ declare module '../types' {
>
>
]
Partialise: [
Expect<Equal<Partialise<Dummy>, Partial<Dummy>>>,
Expect<Equal<Partialise<{ 1: string; 2: number }, 1>, { 1?: string; 2: number }>>
]
}
}
}
5 changes: 5 additions & 0 deletions types/ObjectUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ export namespace ObjectUtils {
type RequireOneOptional<T extends object> = MergeInsertions<
OnlyRequired<T> & SemiPartial<OnlyOptional<T>>
>

/** Make given keys of an object partial */
export type Partialise<T extends object, Keys extends keyof T = keyof T> = MergeInsertions<
Omit<T, Keys> & Partial<Pick<T, keyof T>>
>
}

0 comments on commit 07160ca

Please sign in to comment.