@kakasoo/deep-strict-types 1.0.25 → 1.0.26
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 +55 -38
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# How To Use
|
|
2
|
+
|
|
2
3
|

|
|
3
4
|
|
|
4
5
|
```bash
|
|
@@ -7,11 +8,13 @@ npm i @kakasoo/deep-strict-types
|
|
|
7
8
|
|
|
8
9
|
# DeepStrictTypes
|
|
9
10
|
|
|
10
|
-
**DeepStrictTypes** extends TypeScript utility types, enabling safe operations like `Omit` and `Pick` on nested objects or arrays by specifying
|
|
11
|
+
**DeepStrictTypes** extends TypeScript utility types, enabling safe operations like `Omit` and `Pick` on deeply nested objects or arrays by specifying keys to be inferred. It provides strict and accurate type checks, simplifying tasks like removing a single key from a nested object without recombining multiple types. Quickly and precisely omit or pick the internal keys you need!
|
|
12
|
+
|
|
13
|
+
## Key Features
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
### `DeepStrictObjectKeys`
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
Extract all nested keys from an object `T`, preserving its structure. Useful for safely handling specific keys at deeper levels of an object.
|
|
15
18
|
|
|
16
19
|
```typescript
|
|
17
20
|
type Example = {
|
|
@@ -28,13 +31,13 @@ type Example = {
|
|
|
28
31
|
type Keys = DeepStrictObjectKeys<Example>;
|
|
29
32
|
```
|
|
30
33
|
|
|
31
|
-
In
|
|
34
|
+
In arrays, elements are represented with the `[*]` symbol, ensuring perfect inference even for nested structures.
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
### `DeepStrictOmit`
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
Create a new type by excluding properties corresponding to key `K` from object `T`, preserving the nested structure.
|
|
36
39
|
|
|
37
|
-
```
|
|
40
|
+
```typescript
|
|
38
41
|
type Example = {
|
|
39
42
|
user: {
|
|
40
43
|
name: string;
|
|
@@ -46,42 +49,30 @@ type Example = {
|
|
|
46
49
|
type Omitted = DeepStrictOmit<Example, 'user.name'>;
|
|
47
50
|
```
|
|
48
51
|
|
|
49
|
-
This is
|
|
52
|
+
This is particularly effective for branded types. Below is an example using the `typia` library:
|
|
50
53
|
|
|
51
|
-
```
|
|
52
|
-
test('
|
|
54
|
+
```typescript
|
|
55
|
+
test('Apply DeepStrictOmit to branding types', () => {
|
|
53
56
|
type TestInterface = {
|
|
54
57
|
id: string;
|
|
55
|
-
title: string;
|
|
56
58
|
thumbnails: {
|
|
57
|
-
name:
|
|
58
|
-
extension: null | (string & MinLength<1> & MaxLength<8>);
|
|
59
|
+
name: string & MinLength<1> & MaxLength<255>;
|
|
59
60
|
url: string;
|
|
60
61
|
}[];
|
|
61
62
|
};
|
|
62
63
|
|
|
63
64
|
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
|
-
>;
|
|
65
|
+
type IsAnswer = Equal<Question, { thumbnails: { name: string & MinLength<1> & MaxLength<255>; url: string }[] }>;
|
|
75
66
|
|
|
76
67
|
ok(typia.random<IsAnswer>());
|
|
77
68
|
});
|
|
78
69
|
```
|
|
79
70
|
|
|
80
|
-
|
|
71
|
+
### `DeepStrictPick`
|
|
81
72
|
|
|
82
|
-
|
|
73
|
+
Select properties corresponding to key `K` from object `T`, preserving the nested structure.
|
|
83
74
|
|
|
84
|
-
```
|
|
75
|
+
```typescript
|
|
85
76
|
type Example = {
|
|
86
77
|
user: {
|
|
87
78
|
name: string;
|
|
@@ -93,38 +84,64 @@ type Example = {
|
|
|
93
84
|
type Picked = DeepStrictPick<Example, 'user.name'>;
|
|
94
85
|
```
|
|
95
86
|
|
|
96
|
-
|
|
87
|
+
### `DeepStrictUnbrand`
|
|
97
88
|
|
|
98
|
-
|
|
89
|
+
Remove branding from type `T`, even in deeply nested objects, simplifying the handling of branded types.
|
|
99
90
|
|
|
100
|
-
```
|
|
101
|
-
type BrandedType = {
|
|
91
|
+
```typescript
|
|
92
|
+
type BrandedType = { value: number & { unit: 'dollar' } };
|
|
102
93
|
|
|
103
94
|
// Result: { value: number; }
|
|
104
95
|
type Unbranded = DeepStrictUnbrand<BrandedType>;
|
|
105
96
|
```
|
|
106
97
|
|
|
107
|
-
|
|
98
|
+
### `GetType`
|
|
108
99
|
|
|
109
|
-
|
|
100
|
+
Get the type of a specific key path from a nested object type `T`. This is useful for extracting the type of deeply nested properties safely.
|
|
110
101
|
|
|
111
|
-
|
|
102
|
+
```typescript
|
|
103
|
+
type Example = {
|
|
104
|
+
user: {
|
|
105
|
+
name: string;
|
|
106
|
+
address: {
|
|
107
|
+
city: string;
|
|
108
|
+
zip: number;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// Result: string
|
|
114
|
+
type CityType = GetType<Example, 'user.address.city'>;
|
|
115
|
+
|
|
116
|
+
// Result: { city: string; zip: number; }
|
|
117
|
+
type AddressType = GetType<Example, 'user.address'>;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Utility SubTypes
|
|
112
121
|
|
|
113
|
-
|
|
122
|
+
### `ElementOf`
|
|
123
|
+
|
|
124
|
+
Extract the type of elements from an array type `T`.
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
114
127
|
type ArrayExample = string[];
|
|
115
128
|
|
|
116
129
|
// Result: string
|
|
117
130
|
type ElementType = ElementOf<ArrayExample>;
|
|
118
131
|
```
|
|
119
132
|
|
|
120
|
-
### Equal
|
|
133
|
+
### `Equal`
|
|
121
134
|
|
|
122
|
-
|
|
135
|
+
Evaluate whether types `A` and `B` are the same, returning `true` or `false`. Useful for type validation.
|
|
123
136
|
|
|
124
|
-
```
|
|
137
|
+
```typescript
|
|
125
138
|
type A = { a: number };
|
|
126
139
|
type B = { a: number };
|
|
127
140
|
|
|
128
141
|
// Result: true
|
|
129
142
|
type AreEqual = Equal<A, B>;
|
|
130
143
|
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
This is just a part of the features provided by **DeepStrictTypes**, designed to enhance TypeScript's type manipulation capabilities and improve developer productivity. For more details, check out the library's full documentation.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kakasoo/deep-strict-types",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
4
4
|
"description": "",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"author": "kakasoo",
|
|
48
48
|
"license": "ISC",
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@samchon/shopping-api": "^0.
|
|
51
|
-
"@types/node": "^22.10.
|
|
50
|
+
"@samchon/shopping-api": "^0.14.1",
|
|
51
|
+
"@types/node": "^22.10.10",
|
|
52
52
|
"prettier": "^3.4.2",
|
|
53
53
|
"rimraf": "^6.0.1",
|
|
54
54
|
"ts-patch": "^3.3.0",
|
|
55
|
-
"typescript": "^5.7.
|
|
56
|
-
"typia": "^7.
|
|
55
|
+
"typescript": "^5.7.3",
|
|
56
|
+
"typia": "^7.6.0"
|
|
57
57
|
},
|
|
58
58
|
"repository": {
|
|
59
59
|
"type": "git",
|