@kakasoo/deep-strict-types 1.0.20 → 1.0.22

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,4 +1,5 @@
1
1
  # How To Use
2
+ ![example](https://github.com/user-attachments/assets/28316425-8302-453e-b238-0c732606e6a7)
2
3
 
3
4
  ```bash
4
5
  npm i @kakasoo/deep-strict-types
@@ -6,7 +7,7 @@ npm i @kakasoo/deep-strict-types
6
7
 
7
8
  # DeepStrictTypes
8
9
 
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.
10
+ **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
11
 
11
12
  ## DeepStrictObjectKeys
12
13
 
@@ -14,49 +15,82 @@ npm i @kakasoo/deep-strict-types
14
15
 
15
16
  ```typescript
16
17
  type Example = {
17
- user: {
18
- name: string;
19
- address: {
20
- city: string;
21
- zip: number;
22
- };
18
+ user: {
19
+ name: string;
20
+ address: {
21
+ city: string;
22
+ zip: number;
23
23
  };
24
+ };
24
25
  };
25
26
 
26
27
  // Result: "user" | "user.name" | "user.address" | "user.address.city" | "user.address.zip"
27
28
  type Keys = DeepStrictObjectKeys<Example>;
28
29
  ```
29
30
 
31
+ 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.
32
+
30
33
  ## DeepStrictOmit
31
34
 
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.
35
+ `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
36
 
34
37
  ```ts
35
38
  type Example = {
36
- user: {
37
- name: string;
38
- age: number;
39
- };
39
+ user: {
40
+ name: string;
41
+ age: number;
42
+ };
40
43
  };
41
44
 
42
45
  // Result: { user: { age: number; } }
43
- type Omitted = DeepStrictOmit<Example, "user.name">;
46
+ type Omitted = DeepStrictOmit<Example, 'user.name'>;
47
+ ```
48
+
49
+ 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.
50
+
51
+ ```ts
52
+ test('TEST 1. apply DeepStrictOmit to primitive property type of branding type', () => {
53
+ type TestInterface = {
54
+ id: string;
55
+ title: string;
56
+ thumbnails: {
57
+ name: null | (string & MinLength<1> & MaxLength<255>);
58
+ extension: null | (string & MinLength<1> & MaxLength<8>);
59
+ url: string;
60
+ }[];
61
+ };
62
+
63
+ type Question = DeepStrictOmit<TestInterface, 'id'>;
64
+ type IsAnswer = Equal<
65
+ Question,
66
+ {
67
+ title: string;
68
+ thumbnails: {
69
+ name: null | (string & MinLength<1> & MaxLength<255>);
70
+ extension: null | (string & MinLength<1> & MaxLength<8>);
71
+ url: string;
72
+ }[];
73
+ }
74
+ >;
75
+
76
+ ok(typia.random<IsAnswer>());
77
+ });
44
78
  ```
45
79
 
46
80
  ## DeepStrictPick
47
81
 
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.
82
+ `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
83
 
50
84
  ```ts
51
85
  type Example = {
52
- user: {
53
- name: string;
54
- age: number;
55
- };
86
+ user: {
87
+ name: string;
88
+ age: number;
89
+ };
56
90
  };
57
91
 
58
92
  // Result: { user: { name: string; } }
59
- type Picked = DeepStrictPick<Example, "user.name">;
93
+ type Picked = DeepStrictPick<Example, 'user.name'>;
60
94
  ```
61
95
 
62
96
  ## DeepStrictUnbrand
@@ -64,7 +98,7 @@ type Picked = DeepStrictPick<Example, "user.name">;
64
98
  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
99
 
66
100
  ```ts
67
- type BrandedType = { brand: number & { type: "won" } };
101
+ type BrandedType = { brand: number & { type: 'won' } };
68
102
 
69
103
  // Result: { value: number; }
70
104
  type Unbranded = DeepStrictUnbrand<BrandedType>;
@@ -1,10 +1,10 @@
1
1
  import type { DeepStrictObjectKeys } from './DeepStrictObjectKeys';
2
2
  import type { DeepStrictUnbrand } from './DeepStrictUnbrand';
3
3
  import type { GetElementMember } from './GetMember';
4
- export type ____DeepStrictOmit<T extends object, K extends DeepStrictObjectKeys<T>> = [K] extends [never] ? T : {
4
+ type ____DeepStrictOmit<T extends object, K extends DeepStrictObjectKeys<T>> = [K] extends [never] ? T : {
5
5
  [key in keyof T as key extends K ? never : key]: T[key] extends Array<infer Element extends object> ? key extends string ? Element extends Date ? Array<Element> : GetElementMember<K, key> extends DeepStrictObjectKeys<Element> ? Array<____DeepStrictOmit<Element, GetElementMember<K, key>>> : Array<Element> : never : T[key] extends Array<infer Element> ? Array<Element> : T[key] extends object ? key extends string ? T[key] extends Date ? T[key] : GetElementMember<K, key> extends DeepStrictObjectKeys<T[key]> ? ____DeepStrictOmit<T[key], GetElementMember<K, key>> : T[key] : never : T[key];
6
6
  };
7
- export type _DeepStrictOmit<T extends object, K extends DeepStrictObjectKeys<T>> = T extends Array<infer Element extends object> ? Array<_DeepStrictOmit<Element, GetElementMember<K, ''> extends DeepStrictObjectKeys<Element> ? GetElementMember<K, ''> : never>> : ____DeepStrictOmit<T, K>;
7
+ type _DeepStrictOmit<T extends object, K extends DeepStrictObjectKeys<T>> = T extends Array<infer Element extends object> ? Array<_DeepStrictOmit<Element, GetElementMember<K, ''> extends DeepStrictObjectKeys<Element> ? GetElementMember<K, ''> : never>> : ____DeepStrictOmit<T, K>;
8
8
  /**
9
9
  * @title 인터페이스에서 특정 키를 제거하는 타입.
10
10
  * {@link DeepStrictObjectKeys} 을 이용해서 제거할 키를 고를 수 있다.
@@ -16,4 +16,5 @@ export type _DeepStrictOmit<T extends object, K extends DeepStrictObjectKeys<T>>
16
16
  * ```
17
17
  */
18
18
  export type DeepStrictOmit<T extends object, K extends DeepStrictObjectKeys<DeepStrictUnbrand<T>>> = _DeepStrictOmit<T, Extract<K, DeepStrictObjectKeys<T>>>;
19
+ export {};
19
20
  //# sourceMappingURL=DeepStrictOmit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DeepStrictOmit.d.ts","sourceRoot":"","sources":["../../../src/types/DeepStrictOmit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACrG,CAAC,GACD;KACG,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,KAAK,CAAC,MAAM,OAAO,SAAS,MAAM,CAAC,GAC/F,GAAG,SAAS,MAAM,GAChB,OAAO,SAAS,IAAI,GAClB,KAAK,CAAC,OAAO,CAAC,GACd,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,oBAAoB,CAAC,OAAO,CAAC,GAC5D,KAAK,CAAC,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,GAC5D,KAAK,CAAC,OAAO,CAAC,GAClB,KAAK,GACP,CAAC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CAAC;CACf,CAAC;AAEN,KAAK,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,IACtE,CAAC,SAAS,KAAK,CAAC,MAAM,OAAO,SAAS,MAAM,CAAC,GACzC,KAAK,CACH,eAAe,CACb,OAAO,EACP,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,oBAAoB,CAAC,OAAO,CAAC,GAAG,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,CAChG,CACF,GACD,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE/B;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,oBAAoB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,eAAe,CAClH,CAAC,EACD,OAAO,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC,CACpC,CAAC"}
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.22",
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
  }