@@ -8,6 +8,8 @@ import type { ReturnTypeOf } from "./array-types.js"
8
8
* for better readability.
9
9
*
10
10
* It doesn't change the original object type.
11
+ *
12
+ * @param {object } Obj - The object to prettify
11
13
*/
12
14
export type Prettify < Obj extends object > = {
13
15
[ Property in keyof Obj ] : Obj [ Property ]
@@ -16,6 +18,7 @@ export type Prettify<Obj extends object> = {
16
18
/**
17
19
* It creates a new type based on your object but marks every property as readonly
18
20
*
21
+ * @param {object } Obj - The object to make readonly
19
22
* @example
20
23
* interface User {
21
24
* name: string,
@@ -37,28 +40,35 @@ export type DeepReadonly<Obj extends object> = {
37
40
}
38
41
39
42
/**
40
- * Compare two types and return `never` if the type `T` extends the type `Match`,
41
- * otherwise return the type `T`.
42
- *
43
+ * Conditionally excludes or includes types based on whether `Type` is assignable to `Extends`.
44
+ * If `Reverse` is `true`, it includes types that are assignable to `Extends`, otherwise it excludes them.
45
+ * If `Value` is provided, it returns `Value` instead of `never` when the condition is met.
46
+ *
47
+ * @param {Type } Type - The type to evaluate
48
+ * @param {Extends } Extends - The type to compare against
49
+ * @param {Value } Value - The value to return if the condition is met (defaults to `never`)
50
+ * @param {Reverse } Reverse - If `true`, reverses the condition (defaults to `false`)
43
51
* @example
44
52
* // Expected: number
45
53
* type A = Discard<string | number, string>;
54
+ *
46
55
* // Expected: string | number
47
56
* type B = Discard<string | number, boolean>;
48
57
*/
49
- export type Discard < Compare , Match , Value = never , Reverse extends boolean = false > = Reverse extends true
50
- ? Compare extends Match
58
+ export type Discard < Type , Extends , Value = never , Reverse extends boolean = false > = Reverse extends true
59
+ ? Type extends Extends
51
60
? Value
52
61
: never
53
- : Compare extends Match
62
+ : Type extends Extends
54
63
? never
55
64
: IsNever < Value > extends true
56
- ? Compare
65
+ ? Type
57
66
: Value
58
67
59
68
/**
60
69
* Get the type of the resolved value of a PromiseLike object.
61
70
*
71
+ * @param {PromiseLike<unknown> } T - The PromiseLike object to resolve
62
72
* @example
63
73
* // Expected: string
64
74
* type A = Awaited<Promise<string>>;
@@ -76,6 +86,8 @@ export type Awaited<T extends PromiseLike<unknown>> =
76
86
/**
77
87
* Creates a union of the keys of two objects
78
88
*
89
+ * @param {object } Obj1 - The first object to get the keys from
90
+ * @param {object } Obj2 - The second object to get the keys from
79
91
* @example
80
92
* interface Foo {
81
93
* foo: string,
@@ -96,6 +108,8 @@ export type Properties<Obj1 extends object, Obj2 extends object, Extends extends
96
108
* Creates a new object by merging two objects. Properties from `Obj1` override properties
97
109
* from `Obj2` if they have the same key
98
110
*
111
+ * @param {object } Obj1 - The first object to merge
112
+ * @param {object } Obj2 - The second object to merge
99
113
* @example
100
114
* interface Config {
101
115
* storePaths: string[],
@@ -124,6 +138,8 @@ type IntersectionImplementation<Obj1 extends object, Obj2 extends object, Keys =
124
138
/**
125
139
* Create a new object based in the difference keys between the objects.
126
140
*
141
+ * @param {object } Obj1 - The first object to compare
142
+ * @param {object } Obj2 - The second object to compare
127
143
* @example
128
144
* interface Foo {
129
145
* name: string
@@ -142,8 +158,10 @@ type IntersectionImplementation<Obj1 extends object, Obj2 extends object, Keys =
142
158
export type Intersection < Obj1 extends object , Obj2 extends object > = IntersectionImplementation < Obj1 , Obj2 >
143
159
144
160
/**
145
- * Create a new object based in the type of its keys
161
+ * Create a new object based in the keys that are assignable of type `Type`
146
162
*
163
+ * @param {object } Obj - The object to pick the keys from
164
+ * @param {Type } Type - The type to compare against
147
165
* @example
148
166
* interface User {
149
167
* name: string,
@@ -159,8 +177,11 @@ export type PickByType<Obj extends object, Type> = {
159
177
}
160
178
161
179
/**
162
- * Converts the specified keys of an object into optional ones
180
+ * Converts the specified `Keys` of an object type into optional ones, By default it makes
181
+ * all properties optional.
163
182
*
183
+ * @param {object } Obj - The object to convert
184
+ * @param {string } Keys - The keys to make optional
164
185
* @example
165
186
* interface User {
166
187
* name: string,
@@ -178,6 +199,8 @@ export type PartialByKeys<Obj extends object, Keys extends keyof Obj = keyof Obj
178
199
/**
179
200
* Create a new object based in the keys that are not assignable of type `Type`
180
201
*
202
+ * @param {object } Obj - The object to pick the keys from
203
+ * @param {Type } Type - The type to compare against
181
204
* @example
182
205
* interface User {
183
206
* name: string,
@@ -196,6 +219,8 @@ export type OmitByType<Obj extends object, Type> = {
196
219
* Extracts the value of a key from an object and returns a new object with that value,
197
220
* while keeping the other values unchanged.
198
221
*
222
+ * @param {object } Obj - The object to extract the value from
223
+ * @param {string } Key - The key to extract the value from
199
224
* @example
200
225
* interface User {
201
226
* name: string,
@@ -220,6 +245,7 @@ export type FlattenProperties<Obj extends object, Keys extends keyof Obj> = Pret
220
245
/**
221
246
* Removes the properties whose keys start with an underscore (_).
222
247
*
248
+ * @param {object } Obj - The object to remove the properties from
223
249
* @example
224
250
* interface User {
225
251
* name: string,
@@ -238,8 +264,10 @@ export type PublicOnly<Obj extends object> = {
238
264
* Checks if a key exists in either of the two objects and returns its value.
239
265
* If the key does not exist in either object, it returns `never`.
240
266
*
267
+ * @param {object } Obj1 - The first object to check
268
+ * @param {object } Obj2 - The second object to check
269
+ * @param {string } Key - The key to check
241
270
* @example
242
- *
243
271
* interface Foo {
244
272
* foo: string
245
273
* }
@@ -262,8 +290,11 @@ export type RetrieveKeyValue<Obj1 extends object, Obj2 extends object, Key> = Ke
262
290
263
291
/**
264
292
* Convert to required the keys speficied in the type `Keys`, and the others fields mantein
265
- * their definition. When `Keys` is not provided, it should make all properties required
293
+ * their definition. When `Keys` is not provided, it should make all properties required. By default
294
+ * it makes all properties required.
266
295
*
296
+ * @param {object } Obj - The object to convert
297
+ * @param {string } Keys - The keys to make required
267
298
* @example
268
299
* interface User {
269
300
* name?: string,
@@ -282,6 +313,8 @@ export type RequiredByKeys<Obj extends object, Keys extends keyof Obj = keyof Ob
282
313
*
283
314
* Merge the properties of two objects and it the properties are repeated the types create an union
284
315
*
316
+ * @param {object } Obj1 - The first object to merge
317
+ * @param {object } Obj2 - The second object to merge
285
318
* @example
286
319
* interface Foo {
287
320
* bar: string
@@ -309,6 +342,7 @@ export type UnionMerge<Obj1 extends object, Obj2 extends object> = {
309
342
*
310
343
* **Important:** Only affects top-level properties, not nested properties.
311
344
*
345
+ * @param {object } Obj - The object to convert
312
346
* @example
313
347
* interface User {
314
348
* readonly name: string;
@@ -327,6 +361,7 @@ export type Mutable<Obj extends object> = {
327
361
* Converts all properties to non-readonly of alls levels of the object type,
328
362
* This is an advanced utility type of `Mutable`
329
363
*
364
+ * @param {object } Obj - The object to convert
330
365
* @example
331
366
* interface Foo {
332
367
* readonly foo: {
@@ -357,6 +392,7 @@ type MergeAllImplementation<Array extends readonly object[], Merge extends objec
357
392
* Create a new object type based in the tuple of object types, if the properties
358
393
* are duplicated will create an union type.
359
394
*
395
+ * @param {T[] } Array - The tuple of object types to merge
360
396
* @example
361
397
* interface Foo {
362
398
* foo: string
@@ -380,6 +416,9 @@ export type MergeAll<Array extends readonly object[]> = MergeAllImplementation<A
380
416
/**
381
417
* Create a new object type appending a new property with its value
382
418
*
419
+ * @param {object } Obj - The object to append the property
420
+ * @param {string } NewProp - The new property to append
421
+ * @param {TypeValue } TypeValue - The type of the new property
383
422
* @example
384
423
* interface User {
385
424
* name: string
@@ -395,6 +434,7 @@ export type AddPropertyToObject<Obj extends object, NewProp extends string, Type
395
434
/**
396
435
* Returns a union type of the entries of the provided object
397
436
*
437
+ * @param {object } Obj - The object to get the entries from
398
438
* @example
399
439
* interface Foo {
400
440
* foo: string,
@@ -413,6 +453,10 @@ export type ObjectEntries<Obj extends object, RequiredObj extends object = Requi
413
453
* Replaces the types of the keys in an object with new types defined in the `Replace` object.
414
454
* If a key in `Keys` is not found in `Replace`, it defaults to the `Default` type.
415
455
*
456
+ * @param {object } Obj - The object to replace the keys
457
+ * @param {string } Keys - The keys to replace
458
+ * @param {object } Replace - The new types to replace the keys
459
+ * @param {unknown } Default - The default type if the key is not found in `Replace`
416
460
* @example
417
461
* interface Foo {
418
462
* foo: string,
@@ -435,6 +479,8 @@ export type ReplaceKeys<Obj extends object, Keys extends string, Replace extends
435
479
* Transforms the types of the keys in an object that match the `from` type in the `Mapper`,
436
480
* replacing them with the `to` type in the `Mapper`.
437
481
*
482
+ * @param {object } Obj - The object to map the types
483
+ * @param {object } Mapper - The types to map
438
484
* @example
439
485
* // Expected: { foo: string, bar: boolean }
440
486
* type ReplaceTypesI = MapTypes<{ foo: string, bar: number }, { from: number, to: boolean }>;
@@ -453,8 +499,11 @@ export type MapTypes<Obj extends object, Mapper extends { from: unknown; to: unk
453
499
}
454
500
455
501
/**
456
- * Omits properties of an object at any depth based on the provided pattern.
502
+ * Omits properties of an object at any depth based on the provided pattern string that
503
+ * is a dot-separated path to the property.
457
504
*
505
+ * @param {object } Obj - The object to omit the properties from
506
+ * @param {string } Pattern - The pattern to omit the properties
458
507
* @example
459
508
* type User = {
460
509
* name: string,
@@ -488,6 +537,7 @@ export type DeepOmit<Obj extends object, Pattern extends string> = {
488
537
* Transforms the object properties to their primitive types. If the properties are objects,
489
538
* it recursively transforms their properties to their primitive types, and so on.
490
539
*
540
+ * @param {object } Obj - The object to transform
491
541
* @example
492
542
* interface User {
493
543
* name: "Foo",
@@ -522,6 +572,7 @@ type GetRequiredImplementation<Obj extends object, RequiredKeys extends object =
522
572
* Get only the keys of an object that are required in the object type otherwise
523
573
* remove them from the object type.
524
574
*
575
+ * @param {object } Obj - The object to get the required keys from
525
576
* @example
526
577
* interface User {
527
578
* name: string
@@ -538,6 +589,7 @@ export type GetRequired<Obj extends object> = GetRequiredImplementation<Obj>
538
589
* Get only the keys of an object that are optional in the object type otherwise
539
590
* remove them from the object type
540
591
*
592
+ * @param {object } Obj - The object to get the optional keys from
541
593
* @example
542
594
* interface User {
543
595
* name: string
@@ -556,6 +608,8 @@ export type GetOptional<T extends object> = {
556
608
* Get the value of a key from an object without worrying about the nested properties
557
609
* of the object only should separate the keys with a dot.
558
610
*
611
+ * @param {object } T - The object to get the value from
612
+ * @param {string } K - The key to get the value from
559
613
* @example
560
614
* interface User {
561
615
* foo: {
@@ -580,8 +634,13 @@ export type Get<T, K extends string> = K extends keyof T
580
634
: never
581
635
582
636
/**
637
+ * TODO: This type is the same as `Get` type, but it should be removed in the future or just
638
+ * update the logic to make it different from `Get` type.
639
+ *
583
640
* Picks the properties of an object at any depth based on the provided pattern.
584
641
*
642
+ * @param {object } Obj - The object to pick the properties from
643
+ * @param {string } Pattern - The pattern to pick the properties
585
644
* @example
586
645
* interface User {
587
646
* name: string,
@@ -591,8 +650,9 @@ export type Get<T, K extends string> = K extends keyof T
591
650
* }
592
651
* }
593
652
*
594
- * // Expected: { address: { street: string } }
653
+ * // Expected: string
595
654
* type UserPick = DeepPick<User, "address.street">
655
+ *
596
656
*/
597
657
export type DeepPick < Obj , Pattern > = Pattern extends `${infer Left } .${infer Right } `
598
658
? Left extends keyof Obj
0 commit comments