@kakasoo/deep-strict-types 1.0.0 → 1.0.1

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
@@ -1 +1,90 @@
1
- # DeepStrictTypes
1
+ # DeepStrictTypes
2
+
3
+ **DeepStrictTypes** extends TypeScript utility types, enabling safe operations like `Omit` and `Pick` on nested objects or arrays by specifying the keys to be inferred. This allows for more strict and accurate type checks.
4
+
5
+ ## DeepStrictObjectKeys
6
+
7
+ `DeepStrictObjectKeys<T>` extracts all nested keys from an object `T`, preserving the structure of the nested object and returning the types of the keys. This is useful when you need to handle specific keys safely at deeper levels of an object.
8
+
9
+ ```typescript
10
+ type Example = {
11
+ user: {
12
+ name: string;
13
+ address: {
14
+ city: string;
15
+ zip: number;
16
+ };
17
+ };
18
+ };
19
+
20
+ // Result: "user" | "user.name" | "user.address" | "user.address.city" | "user.address.zip"
21
+ type Keys = DeepStrictObjectKeys<Example>;
22
+ ```
23
+
24
+ ## DeepStrictOmit
25
+
26
+ DeepStrictOmit<T, K> creates a new type by excluding properties corresponding to the key K from object T, while preserving the nested structure. This type allows precise omission of keys even in deeply nested objects.
27
+
28
+ ```ts
29
+ type Example = {
30
+ user: {
31
+ name: string;
32
+ age: number;
33
+ };
34
+ };
35
+
36
+ // Result: { user: { age: number; } }
37
+ type Omitted = DeepStrictOmit<Example, "user.name">;
38
+ ```
39
+
40
+ ## DeepStrictPick
41
+
42
+ DeepStrictPick<T, K> creates a new type by selecting only the properties corresponding to the key K from object T, while preserving the nested structure. It allows safely selecting specific keys even from deep objects.
43
+
44
+ ```ts
45
+ type Example = {
46
+ user: {
47
+ name: string;
48
+ age: number;
49
+ };
50
+ };
51
+
52
+ // Result: { user: { name: string; } }
53
+ type Picked = DeepStrictPick<Example, "user.name">;
54
+ ```
55
+
56
+ ## DeepStrictUnbrand
57
+
58
+ DeepStrictUnbrand<T> removes branding from type T and applies it even to deeply nested objects. This makes handling complex branded types simpler by removing the branding for more straightforward use.
59
+
60
+ ```ts
61
+ type BrandedType = { brand: number & { type: "won" } };
62
+
63
+ // Result: { value: number; }
64
+ type Unbranded = DeepStrictUnbrand<BrandedType>;
65
+ ```
66
+
67
+ ## SubTypes for implementation
68
+
69
+ ### ElementOf
70
+
71
+ ElementOf<T> extracts the type of elements from an array type T. This is useful to explicitly define the element type of an array and perform operations on that element.
72
+
73
+ ```ts
74
+ type ArrayExample = string[];
75
+
76
+ // Result: string
77
+ type ElementType = ElementOf<ArrayExample>;
78
+ ```
79
+
80
+ ### Equal
81
+
82
+ Equal<A, B> evaluates whether types A and B are the same and returns true or false. This is used to validate whether two types are identical.
83
+
84
+ ```ts
85
+ type A = { a: number };
86
+ type B = { a: number };
87
+
88
+ // Result: true
89
+ type AreEqual = Equal<A, B>;
90
+ ```
@@ -1,7 +1,7 @@
1
1
  type Primitive = string | number | boolean | symbol | null | undefined;
2
- type Unbrand<T extends Primitive & NonNullable<unknown>> = T extends Primitive & NonNullable<unknown> ? Extract<Primitive, T> : never;
2
+ type Unbrand<T extends Primitive & Record<any, any>> = T extends string & Record<any, any> ? Extract<string, Omit<T, any>> : T extends number & Record<any, any> ? Extract<number, Omit<T, any>> : T extends boolean & Record<any, any> ? Extract<boolean, Omit<T, any>> : T extends symbol & Record<any, any> ? Extract<symbol, Omit<T, any>> : T extends null & Record<any, any> ? Extract<null, Omit<T, any>> : T extends undefined & Record<any, any> ? Extract<undefined, Omit<T, any>> : T;
3
3
  export type DeepStrictUnbrand<T> = T extends Array<Date> ? Array<Date> : T extends Array<infer I extends object> ? Array<DeepStrictUnbrand<I>> : T extends Primitive & NonNullable<unknown> ? Unbrand<T> : T extends Date ? T : {
4
- [K in keyof T]: T[K] extends Unbrand<infer I> ? Extract<I, T[K]> : T[K] extends object ? DeepStrictUnbrand<T[K]> : T[K];
4
+ [K in keyof T]: T[K] extends object ? DeepStrictUnbrand<T[K]> : T[K];
5
5
  };
6
6
  export {};
7
7
  //# sourceMappingURL=DeepStrictUnbrand.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DeepStrictUnbrand.d.ts","sourceRoot":"","sources":["../../../src/types/DeepStrictUnbrand.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AACvE,KAAK,OAAO,CAAC,CAAC,SAAS,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,SAAS,GAC1E,WAAW,CAAC,OAAO,CAAC,GAClB,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,GACrB,KAAK,CAAC;AAEZ,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,IAAI,CAAC,GAClD,KAAK,CAAC,IAAI,CAAC,GACX,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,SAAS,MAAM,CAAC,GACvC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAC3B,CAAC,SAAS,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC,GAC1C,OAAO,CAAC,CAAC,CAAC,GACV,CAAC,SAAS,IAAI,GACd,CAAC,GACD;KACK,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GACvC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAChB,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GACnB,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACvB,CAAC,CAAC,CAAC,CAAC;CACb,CAAC"}
1
+ {"version":3,"file":"DeepStrictUnbrand.d.ts","sourceRoot":"","sources":["../../../src/types/DeepStrictUnbrand.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SA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O,CAAC,CAAC,CAAC,GACV,CAAC,SAAS,IAAI,GACd,CAAC,GACD;KACK,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACvE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kakasoo/deep-strict-types",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -15,7 +15,7 @@
15
15
  "build": "rimraf dist && tsc",
16
16
  "build:test": "rimraf bin && tsc -p test/tsconfig.json --watch",
17
17
  "prepare": "ts-patch install && typia patch",
18
- "test": "node --watch bin/test/*.js"
18
+ "test": "node bin/test/index.js"
19
19
  },
20
20
  "keywords": [],
21
21
  "author": "",