@kakasoo/deep-strict-types 1.0.20 → 1.0.21

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.
Files changed (2) hide show
  1. package/README.md +53 -20
  2. package/package.json +32 -3
package/README.md CHANGED
@@ -6,7 +6,7 @@ npm i @kakasoo/deep-strict-types
6
6
 
7
7
  # DeepStrictTypes
8
8
 
9
- **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.
9
+ **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. **Now, you don't have to recombine numerous types daily to remove a single key from a nested object. You can quickly omit and pick the internal keys you want!**
10
10
 
11
11
  ## DeepStrictObjectKeys
12
12
 
@@ -14,49 +14,82 @@ npm i @kakasoo/deep-strict-types
14
14
 
15
15
  ```typescript
16
16
  type Example = {
17
- user: {
18
- name: string;
19
- address: {
20
- city: string;
21
- zip: number;
22
- };
17
+ user: {
18
+ name: string;
19
+ address: {
20
+ city: string;
21
+ zip: number;
23
22
  };
23
+ };
24
24
  };
25
25
 
26
26
  // Result: "user" | "user.name" | "user.address" | "user.address.city" | "user.address.zip"
27
27
  type Keys = DeepStrictObjectKeys<Example>;
28
28
  ```
29
29
 
30
+ In the case of an array, the inside is represented by the `[*]` symbol. Of course, the arrangement of the array, the arrangement of objects in the array, and even if the top object is an array, it is perfectly inferred.
31
+
30
32
  ## DeepStrictOmit
31
33
 
32
- 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.
34
+ `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.
33
35
 
34
36
  ```ts
35
37
  type Example = {
36
- user: {
37
- name: string;
38
- age: number;
39
- };
38
+ user: {
39
+ name: string;
40
+ age: number;
41
+ };
40
42
  };
41
43
 
42
44
  // Result: { user: { age: number; } }
43
- type Omitted = DeepStrictOmit<Example, "user.name">;
45
+ type Omitted = DeepStrictOmit<Example, 'user.name'>;
46
+ ```
47
+
48
+ This is also useful for branding types. Below is an example of defining a branding type using a library called typia, in which DeepStrictOmit can also be safely used.
49
+
50
+ ```ts
51
+ test('TEST 1. apply DeepStrictOmit to primitive property type of branding type', () => {
52
+ type TestInterface = {
53
+ id: string;
54
+ title: string;
55
+ thumbnails: {
56
+ name: null | (string & MinLength<1> & MaxLength<255>);
57
+ extension: null | (string & MinLength<1> & MaxLength<8>);
58
+ url: string;
59
+ }[];
60
+ };
61
+
62
+ type Question = DeepStrictOmit<TestInterface, 'id'>;
63
+ type IsAnswer = Equal<
64
+ Question,
65
+ {
66
+ title: string;
67
+ thumbnails: {
68
+ name: null | (string & MinLength<1> & MaxLength<255>);
69
+ extension: null | (string & MinLength<1> & MaxLength<8>);
70
+ url: string;
71
+ }[];
72
+ }
73
+ >;
74
+
75
+ ok(typia.random<IsAnswer>());
76
+ });
44
77
  ```
45
78
 
46
79
  ## DeepStrictPick
47
80
 
48
- 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.
81
+ `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.
49
82
 
50
83
  ```ts
51
84
  type Example = {
52
- user: {
53
- name: string;
54
- age: number;
55
- };
85
+ user: {
86
+ name: string;
87
+ age: number;
88
+ };
56
89
  };
57
90
 
58
91
  // Result: { user: { name: string; } }
59
- type Picked = DeepStrictPick<Example, "user.name">;
92
+ type Picked = DeepStrictPick<Example, 'user.name'>;
60
93
  ```
61
94
 
62
95
  ## DeepStrictUnbrand
@@ -64,7 +97,7 @@ type Picked = DeepStrictPick<Example, "user.name">;
64
97
  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.
65
98
 
66
99
  ```ts
67
- type BrandedType = { brand: number & { type: "won" } };
100
+ type BrandedType = { brand: number & { type: 'won' } };
68
101
 
69
102
  // Result: { value: number; }
70
103
  type Unbranded = DeepStrictUnbrand<BrandedType>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kakasoo/deep-strict-types",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -18,8 +18,33 @@
18
18
  "test": "node bin/test/index.js",
19
19
  "prettier": "prettier src --write && prettier test --write"
20
20
  },
21
- "keywords": [],
22
- "author": "",
21
+ "keywords": [
22
+ "typescript",
23
+ "types",
24
+ "utility-types",
25
+ "deep-types",
26
+ "nested-types",
27
+ "type-safety",
28
+ "type-checking",
29
+ "strict-types",
30
+ "deep-strict",
31
+ "deep-pick",
32
+ "deep-omit",
33
+ "deep-keys",
34
+ "deep-object",
35
+ "type-utils",
36
+ "type-helpers",
37
+ "typescript-utils",
38
+ "typescript-types",
39
+ "type-manipulation",
40
+ "nested-objects",
41
+ "object-types",
42
+ "array-types",
43
+ "type-inference",
44
+ "type-assertions",
45
+ "type-validation"
46
+ ],
47
+ "author": "kakasoo",
23
48
  "license": "ISC",
24
49
  "devDependencies": {
25
50
  "@samchon/shopping-api": "^0.12.1",
@@ -30,6 +55,10 @@
30
55
  "typescript": "^5.7.2",
31
56
  "typia": "^7.5.1"
32
57
  },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/kakasoo/deepstricttypes"
61
+ },
33
62
  "dependencies": {
34
63
  "@kakasoo/proto-typescript": "^1.28.7"
35
64
  }