@guillaume-docquier/tools-ts 10.1.11 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -97,6 +97,7 @@ These exports are type-only helpers for common TypeScript modeling problems.
97
97
  | `Prettify` | Re-expands an object type for easier editor hovers. | Intersections or mapped types are correct but hard to read in tooling. |
98
98
  | `OmitOverUnion` | Applies `Omit` distributively across union members. | Native `Omit` collapses a discriminated union in a way that loses member-specific fields. |
99
99
  | `PartialProperties` | Makes selected object properties partial, not the whole object. | Only nested property objects should become partial while the parent shape stays required. |
100
+ | `PartialOrUndefinedKeys` | Makes all properties optional and allows explicit `undefined`. | An object input should accept omitted keys and keys set to `undefined`. |
100
101
  | `Mutable` | Removes `readonly` from selected properties. | You have a narrow, deliberate mutation need. Avoid this unless there is no cleaner model. |
101
102
 
102
103
  ### Logging
@@ -123,6 +123,19 @@ export type Mutable<T, K extends keyof T> = {
123
123
  export type PartialProperties<TObject, TKey extends keyof TObject> = Omit<TObject, TKey> & {
124
124
  [TProperty in TKey]: Partial<TObject[TProperty]>;
125
125
  };
126
+ /**
127
+ * Makes properties optional and allows them to be set to `undefined`.
128
+ * This is useful when using exactOptionalPropertyTypes and Partial is not enough.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * type Options = PartialOrUndefinedKeys<{ id: string; retries: number | undefined }>
133
+ * // { id?: string | undefined; retries?: number | undefined }
134
+ * ```
135
+ */
136
+ export type PartialOrUndefinedKeys<T> = {
137
+ [K in keyof T]?: T[K] | undefined;
138
+ };
126
139
  /**
127
140
  * Like keyof T, but for the values.
128
141
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guillaume-docquier/tools-ts",
3
- "version": "10.1.11",
3
+ "version": "10.2.0",
4
4
  "description": "My personal collection of typescript tools",
5
5
  "homepage": "https://github.com/Guillaume-Docquier/tools-ts",
6
6
  "license": "MIT",