@inzero/ts-ut 0.5.0 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.0] 2026-11-21
4
+
5
+ ### Added
6
+
7
+ - Added dict convert utils: `OptionalToUndefined<T>` and `OptionalToUndefinedDeep<T>` which convert optional properties into required properties whose values may be undefined.
8
+ - Added `IsUnion<T>` internal utility.
9
+
10
+ ### Fixed
11
+
12
+ - Restrict recursion in `(Required|Partial|Mutable|Readonly)Deep<T>` to objects only, preventing unintended modifications to non-object types: `PartialDeep<string[]>` used to produce `(string | undefined)[]`.
13
+
3
14
  ## [0.5.0] 2026-11-15
4
15
 
5
16
  ### Added
@@ -31,4 +31,6 @@ type _IsReadonlyKey<T, K extends keyof T> = AreNotEqual<{
31
31
  }, {
32
32
  -readonly [P in K]: T[P];
33
33
  }>;
34
+ export type IsUnion<T> = _IsUnion<T>;
35
+ type _IsUnion<T, C = T> = T extends T ? ([C] extends [T] ? false : true) : never;
34
36
  export {};
@@ -0,0 +1,19 @@
1
+ import type { Dict } from "./utils";
2
+ /**
3
+ * Convert optional properties to required ones that can be `undefined`
4
+ *
5
+ * @example
6
+ * type R1 = OptionalToUndefined<{ a: 1, b?: 2 }>; // { a: 1, b: 2 | undefined }
7
+ */
8
+ export type OptionalToUndefined<T> = T extends T ? {
9
+ [P in keyof Required<T>]: T[P];
10
+ } & {} : never;
11
+ /**
12
+ * Deeply convert optional properties to required ones that can be `undefined`.
13
+ *
14
+ * @example
15
+ * type R1 = OptionalToUndefinedDeep<{ a: 1, b?: { c?: 4 } }>; // { a: 1, b: { c: 4 | undefined } | undefined }
16
+ */
17
+ export type OptionalToUndefinedDeep<T> = T extends T ? {
18
+ [P in keyof Required<T>]: T[P] extends infer TP ? TP extends Dict ? OptionalToUndefinedDeep<TP> : TP : never;
19
+ } & {} : never;
@@ -1,3 +1,4 @@
1
+ export * from "./convert";
1
2
  export * from "./extract";
2
3
  export * from "./get";
3
4
  export * from "./keyof";
@@ -1,6 +1,6 @@
1
1
  import type { Keys } from "./keyof";
2
2
  import type { LooseOmit } from "./pick";
3
- import type { Known, Prettify } from "./utils";
3
+ import type { Dict, Known, Prettify } from "./utils";
4
4
  /**
5
5
  * Makes all properties of `T` mutable.
6
6
  */
@@ -11,25 +11,25 @@ export type Mutable<T> = {
11
11
  * Makes all properties of `T` required (deep).
12
12
  */
13
13
  export type RequiredDeep<T> = {
14
- [P in keyof T]-?: RequiredDeep<T[P]>;
14
+ [P in keyof T]-?: T[P] extends infer TP ? (TP extends Dict ? RequiredDeep<TP> : TP) : never;
15
15
  } & {};
16
16
  /**
17
17
  * Makes all properties of `T` optional (deep).
18
18
  */
19
19
  export type PartialDeep<T> = {
20
- [P in keyof T]?: PartialDeep<T[P]>;
20
+ [P in keyof T]?: T[P] extends infer TP ? (TP extends Dict ? PartialDeep<TP> : TP) : never;
21
21
  } & {};
22
22
  /**
23
23
  * Makes all properties of `T` readonly (deep).
24
24
  */
25
25
  export type ReadonlyDeep<T> = {
26
- readonly [P in keyof T]: ReadonlyDeep<T[P]>;
26
+ readonly [P in keyof T]: T[P] extends infer TP ? (TP extends Dict ? ReadonlyDeep<TP> : TP) : never;
27
27
  } & {};
28
28
  /**
29
29
  * Makes all properties of `T` mutable (deep).
30
30
  */
31
31
  export type MutableDeep<T> = {
32
- -readonly [P in keyof T]: MutableDeep<T[P]>;
32
+ -readonly [P in keyof T]: T[P] extends infer TP ? (TP extends Dict ? MutableDeep<TP> : TP) : never;
33
33
  } & {};
34
34
  /**
35
35
  * Makes a property of `T` required.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzero/ts-ut",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "TypeScript Utility Types",
5
5
  "keywords": [
6
6
  "typescript",