type-fest 4.41.0 → 5.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.
Files changed (156) hide show
  1. package/index.d.ts +174 -153
  2. package/package.json +20 -44
  3. package/readme.md +45 -68
  4. package/source/all-extend.d.ts +115 -0
  5. package/source/all-union-fields.d.ts +12 -12
  6. package/source/and.d.ts +60 -8
  7. package/source/array-slice.d.ts +11 -11
  8. package/source/array-splice.d.ts +4 -4
  9. package/source/array-tail.d.ts +40 -48
  10. package/source/arrayable.d.ts +2 -2
  11. package/source/asyncify.d.ts +1 -1
  12. package/source/basic.d.ts +1 -33
  13. package/source/camel-case.d.ts +6 -6
  14. package/source/camel-cased-properties-deep.d.ts +7 -7
  15. package/source/camel-cased-properties.d.ts +4 -4
  16. package/source/characters.d.ts +60 -0
  17. package/source/conditional-except.d.ts +4 -4
  18. package/source/conditional-keys.d.ts +33 -19
  19. package/source/conditional-pick-deep.d.ts +9 -9
  20. package/source/conditional-pick.d.ts +3 -3
  21. package/source/conditional-simplify-deep.d.ts +71 -0
  22. package/source/conditional-simplify.d.ts +36 -20
  23. package/source/delimiter-case.d.ts +9 -12
  24. package/source/delimiter-cased-properties-deep.d.ts +4 -4
  25. package/source/delimiter-cased-properties.d.ts +3 -3
  26. package/source/distributed-omit.d.ts +1 -1
  27. package/source/distributed-pick.d.ts +1 -1
  28. package/source/enforce-optional.d.ts +1 -1
  29. package/source/entries.d.ts +1 -1
  30. package/source/exact.d.ts +6 -6
  31. package/source/except.d.ts +2 -2
  32. package/source/exclude-strict.d.ts +45 -0
  33. package/source/extends-strict.d.ts +42 -0
  34. package/source/extract-strict.d.ts +45 -0
  35. package/source/find-global-type.d.ts +1 -1
  36. package/source/fixed-length-array.d.ts +2 -2
  37. package/source/get.d.ts +15 -14
  38. package/source/globals/index.d.ts +1 -0
  39. package/source/{observable-like.d.ts → globals/observable-like.d.ts} +10 -0
  40. package/source/greater-than-or-equal.d.ts +1 -1
  41. package/source/greater-than.d.ts +9 -9
  42. package/source/has-optional-keys.d.ts +1 -1
  43. package/source/has-readonly-keys.d.ts +1 -1
  44. package/source/has-required-keys.d.ts +1 -1
  45. package/source/has-writable-keys.d.ts +1 -1
  46. package/source/if-any.d.ts +3 -1
  47. package/source/if-empty-object.d.ts +3 -1
  48. package/source/if-never.d.ts +3 -1
  49. package/source/if-null.d.ts +3 -1
  50. package/source/if-unknown.d.ts +3 -1
  51. package/source/if.d.ts +65 -0
  52. package/source/includes.d.ts +1 -1
  53. package/source/int-closed-range.d.ts +2 -2
  54. package/source/int-range.d.ts +6 -4
  55. package/source/internal/array.d.ts +54 -22
  56. package/source/internal/characters.d.ts +0 -4
  57. package/source/internal/index.d.ts +8 -8
  58. package/source/internal/keys.d.ts +24 -23
  59. package/source/internal/numeric.d.ts +45 -15
  60. package/source/internal/object.d.ts +58 -29
  61. package/source/internal/string.d.ts +4 -14
  62. package/source/internal/tuple.d.ts +4 -4
  63. package/source/internal/type.d.ts +34 -43
  64. package/source/is-any.d.ts +0 -4
  65. package/source/is-float.d.ts +1 -1
  66. package/source/is-integer.d.ts +4 -4
  67. package/source/is-literal.d.ts +44 -28
  68. package/source/is-lowercase.d.ts +36 -0
  69. package/source/is-nullable.d.ts +28 -0
  70. package/source/is-optional-key-of.d.ts +49 -0
  71. package/source/is-optional.d.ts +26 -0
  72. package/source/is-readonly-key-of.d.ts +53 -0
  73. package/source/is-required-key-of.d.ts +49 -0
  74. package/source/is-tuple.d.ts +15 -14
  75. package/source/is-undefined.d.ts +20 -0
  76. package/source/is-union.d.ts +37 -0
  77. package/source/is-unknown.d.ts +1 -1
  78. package/source/is-uppercase.d.ts +36 -0
  79. package/source/is-writable-key-of.d.ts +49 -0
  80. package/source/json-value.d.ts +31 -0
  81. package/source/jsonifiable.d.ts +1 -1
  82. package/source/jsonify.d.ts +18 -14
  83. package/source/kebab-case.d.ts +3 -3
  84. package/source/kebab-cased-properties-deep.d.ts +4 -4
  85. package/source/kebab-cased-properties.d.ts +4 -4
  86. package/source/{string-key-of.d.ts → key-as-string.d.ts} +5 -5
  87. package/source/keys-of-union.d.ts +1 -1
  88. package/source/less-than-or-equal.d.ts +1 -1
  89. package/source/less-than.d.ts +1 -1
  90. package/source/literal-to-primitive-deep.d.ts +2 -2
  91. package/source/literal-union.d.ts +1 -1
  92. package/source/merge-deep.d.ts +43 -34
  93. package/source/merge.d.ts +5 -5
  94. package/source/multidimensional-array.d.ts +2 -2
  95. package/source/multidimensional-readonly-array.d.ts +2 -2
  96. package/source/non-empty-object.d.ts +2 -2
  97. package/source/numeric.d.ts +4 -4
  98. package/source/omit-deep.d.ts +11 -11
  99. package/source/opaque.d.ts +1 -1
  100. package/source/optional-keys-of.d.ts +10 -5
  101. package/source/or.d.ts +67 -7
  102. package/source/override-properties.d.ts +1 -1
  103. package/source/package-json.d.ts +78 -78
  104. package/source/partial-deep.d.ts +22 -21
  105. package/source/partial-on-undefined-deep.d.ts +5 -4
  106. package/source/pascal-case.d.ts +13 -6
  107. package/source/pascal-cased-properties-deep.d.ts +11 -3
  108. package/source/pascal-cased-properties.d.ts +7 -3
  109. package/source/paths.d.ts +42 -39
  110. package/source/pick-deep.d.ts +6 -6
  111. package/source/readonly-deep.d.ts +2 -2
  112. package/source/readonly-keys-of.d.ts +10 -4
  113. package/source/remove-prefix.d.ts +128 -0
  114. package/source/replace.d.ts +1 -1
  115. package/source/require-all-or-none.d.ts +8 -7
  116. package/source/require-at-least-one.d.ts +10 -9
  117. package/source/require-exactly-one.d.ts +8 -7
  118. package/source/require-one-or-none.d.ts +9 -8
  119. package/source/required-deep.d.ts +26 -32
  120. package/source/required-keys-of.d.ts +4 -4
  121. package/source/schema.d.ts +74 -74
  122. package/source/screaming-snake-case.d.ts +4 -4
  123. package/source/set-field-type.d.ts +2 -2
  124. package/source/set-non-nullable-deep.d.ts +6 -6
  125. package/source/set-optional.d.ts +11 -5
  126. package/source/set-parameter-type.d.ts +7 -7
  127. package/source/set-readonly.d.ts +12 -9
  128. package/source/set-required-deep.d.ts +12 -12
  129. package/source/set-required.d.ts +15 -8
  130. package/source/set-return-type.d.ts +1 -1
  131. package/source/shared-union-fields-deep.d.ts +10 -10
  132. package/source/shared-union-fields.d.ts +5 -4
  133. package/source/simplify-deep.d.ts +3 -3
  134. package/source/single-key-object.d.ts +4 -3
  135. package/source/snake-case.d.ts +3 -3
  136. package/source/snake-cased-properties-deep.d.ts +4 -4
  137. package/source/snake-cased-properties.d.ts +4 -4
  138. package/source/split.d.ts +9 -9
  139. package/source/spread.d.ts +3 -3
  140. package/source/string-repeat.d.ts +2 -2
  141. package/source/string-slice.d.ts +3 -3
  142. package/source/structured-cloneable.d.ts +25 -25
  143. package/source/subtract.d.ts +3 -3
  144. package/source/sum.d.ts +3 -3
  145. package/source/tagged-union.d.ts +1 -1
  146. package/source/tagged.d.ts +3 -1
  147. package/source/trim.d.ts +1 -1
  148. package/source/tsconfig-json.d.ts +2 -1
  149. package/source/tuple-to-object.d.ts +5 -4
  150. package/source/undefined-on-partial-deep.d.ts +1 -1
  151. package/source/union-to-tuple.d.ts +2 -2
  152. package/source/value-of.d.ts +1 -1
  153. package/source/words.d.ts +5 -5
  154. package/source/writable-deep.d.ts +1 -1
  155. package/source/writable-keys-of.d.ts +5 -6
  156. package/source/writable.d.ts +4 -4
@@ -1,12 +1,12 @@
1
- import type {ArraySplice} from './array-splice';
2
- import type {ExactKey, IsArrayReadonly, NonRecursiveType, SetArrayAccess, ToString} from './internal';
3
- import type {IsEqual} from './is-equal';
4
- import type {IsNever} from './is-never';
5
- import type {LiteralUnion} from './literal-union';
6
- import type {Paths} from './paths';
7
- import type {SimplifyDeep} from './simplify-deep';
8
- import type {UnionToTuple} from './union-to-tuple';
9
- import type {UnknownArray} from './unknown-array';
1
+ import type {ArraySplice} from './array-splice.d.ts';
2
+ import type {ExactKey, IsArrayReadonly, NonRecursiveType, SetArrayAccess, ToString} from './internal/index.d.ts';
3
+ import type {IsEqual} from './is-equal.d.ts';
4
+ import type {IsNever} from './is-never.d.ts';
5
+ import type {LiteralUnion} from './literal-union.d.ts';
6
+ import type {Paths} from './paths.d.ts';
7
+ import type {SimplifyDeep} from './simplify-deep.d.ts';
8
+ import type {UnionToTuple} from './union-to-tuple.d.ts';
9
+ import type {UnknownArray} from './unknown-array.d.ts';
10
10
 
11
11
  /**
12
12
  Omit properties from a deeply-nested object.
@@ -92,8 +92,8 @@ type AddressInfo = OmitDeep<Info1, 'address.1.foo'>;
92
92
  */
93
93
  export type OmitDeep<T, PathUnion extends LiteralUnion<Paths<T>, string>> =
94
94
  SimplifyDeep<
95
- OmitDeepHelper<T, UnionToTuple<PathUnion>>,
96
- UnknownArray>;
95
+ OmitDeepHelper<T, UnionToTuple<PathUnion>>,
96
+ UnknownArray>;
97
97
 
98
98
  /**
99
99
  Internal helper for {@link OmitDeep}.
@@ -1 +1 @@
1
- export * from './tagged';
1
+ export type * from './tagged.d.ts';
@@ -1,3 +1,5 @@
1
+ import type {IsOptionalKeyOf} from './is-optional-key-of.d.ts';
2
+
1
3
  /**
2
4
  Extract all optional keys from the given type.
3
5
 
@@ -31,9 +33,12 @@ const update2: UpdateOperation<User> = {
31
33
 
32
34
  @category Utilities
33
35
  */
34
- export type OptionalKeysOf<BaseType extends object> =
35
- BaseType extends unknown // For distributing `BaseType`
36
- ? (keyof {
37
- [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
38
- }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
36
+ export type OptionalKeysOf<Type extends object> =
37
+ Type extends unknown // For distributing `Type`
38
+ ? (keyof {[Key in keyof Type as
39
+ IsOptionalKeyOf<Type, Key> extends false
40
+ ? never
41
+ : Key
42
+ ]: never
43
+ }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
39
44
  : never; // Should never happen
package/source/or.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type {IsEqual} from './is-equal';
1
+ import type {If} from './if.d.ts';
2
+ import type {IsNever} from './is-never.d.ts';
2
3
 
3
4
  /**
4
5
  Returns a boolean for whether either of two given types are true.
@@ -9,17 +10,76 @@ Use-case: Constructing complex conditional types where multiple conditions must
9
10
  ```
10
11
  import type {Or} from 'type-fest';
11
12
 
12
- Or<true, false>;
13
+ type TT = Or<true, false>;
13
14
  //=> true
14
15
 
15
- Or<false, false>;
16
+ type TF = Or<true, false>;
17
+ //=> true
18
+
19
+ type FT = Or<false, true>;
20
+ //=> true
21
+
22
+ type FF = Or<false, false>;
23
+ //=> false
24
+ ```
25
+
26
+ Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
27
+ For example, `And<false, boolean>` expands to `And<false, true> | And<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
28
+ @example
29
+ ```
30
+ import type {And} from 'type-fest';
31
+
32
+ type A = Or<false, boolean>;
33
+ //=> boolean
34
+
35
+ type B = Or<boolean, false>;
36
+ //=> boolean
37
+
38
+ type C = Or<true, boolean>;
39
+ //=> true
40
+
41
+ type D = Or<boolean, true>;
42
+ //=> true
43
+
44
+ type E = Or<boolean, boolean>;
45
+ //=> boolean
46
+ ```
47
+
48
+ Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
49
+
50
+ @example
51
+ ```
52
+ import type {Or} from 'type-fest';
53
+
54
+ type A = Or<true, never>;
55
+ //=> true
56
+
57
+ type B = Or<never, true>;
58
+ //=> true
59
+
60
+ type C = Or<false, never>;
61
+ //=> false
62
+
63
+ type D = Or<never, false>;
64
+ //=> false
65
+
66
+ type E = Or<boolean, never>;
67
+ //=> boolean
68
+
69
+ type F = Or<never, boolean>;
70
+ //=> boolean
71
+
72
+ type G = Or<never, never>;
16
73
  //=> false
17
74
  ```
18
75
 
19
76
  @see {@link And}
20
77
  */
21
- export type Or<A extends boolean, B extends boolean> = [A, B][number] extends false
22
- ? false
23
- : true extends [IsEqual<A, true>, IsEqual<B, true>][number]
78
+ export type Or<A extends boolean, B extends boolean> =
79
+ _Or<If<IsNever<A>, false, A>, If<IsNever<B>, false, B>>; // `never` is treated as `false`
80
+
81
+ export type _Or<A extends boolean, B extends boolean> = A extends true
82
+ ? true
83
+ : B extends true
24
84
  ? true
25
- : never;
85
+ : false;
@@ -1,4 +1,4 @@
1
- import type {Merge} from './merge';
1
+ import type {Merge} from './merge.d.ts';
2
2
 
3
3
  /**
4
4
  Override existing properties of the given type. Similar to `Merge`, but enforces that the original type has the properties you want to override.
@@ -1,5 +1,5 @@
1
- import type {LiteralUnion} from './literal-union';
2
- import type {JsonObject, JsonValue} from './basic';
1
+ import type {LiteralUnion} from './literal-union.d.ts';
2
+ import type {JsonObject, JsonValue} from './json-value.d.ts';
3
3
 
4
4
  declare namespace PackageJson {
5
5
  /**
@@ -211,7 +211,7 @@ declare namespace PackageJson {
211
211
  /**
212
212
  A mapping of conditions and the paths to which they resolve.
213
213
  */
214
- type ExportConditions = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
214
+ type ExportConditions = {
215
215
  [condition: string]: Exports;
216
216
  };
217
217
 
@@ -219,15 +219,15 @@ declare namespace PackageJson {
219
219
  Entry points of a module, optionally with conditions and subpath exports.
220
220
  */
221
221
  export type Exports =
222
- | null
223
- | string
224
- | Array<string | ExportConditions>
225
- | ExportConditions;
222
+ | null
223
+ | string
224
+ | Array<string | ExportConditions>
225
+ | ExportConditions;
226
226
 
227
227
  /**
228
228
  Import map entries of a module, optionally with conditions and subpath imports.
229
229
  */
230
- export type Imports = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
230
+ export type Imports = {
231
231
  [key: `#${string}`]: Exports;
232
232
  };
233
233
 
@@ -242,19 +242,19 @@ declare namespace PackageJson {
242
242
  A module ID with untranspiled code that is the primary entry point to the program.
243
243
  */
244
244
  esnext?:
245
- | string
246
- | {
247
- [moduleName: string]: string | undefined;
248
- main?: string;
249
- browser?: string;
250
- };
245
+ | string
246
+ | {
247
+ [moduleName: string]: string | undefined;
248
+ main?: string;
249
+ browser?: string;
250
+ };
251
251
 
252
252
  /**
253
253
  A hint to JavaScript bundlers or component tools when packaging modules for client side use.
254
254
  */
255
255
  browser?:
256
- | string
257
- | Partial<Record<string, string | false>>;
256
+ | string
257
+ | Partial<Record<string, string | false>>;
258
258
 
259
259
  /**
260
260
  Denote which files in your project are "pure" and therefore safe for Webpack to prune if unused.
@@ -426,8 +426,8 @@ declare namespace PackageJson {
426
426
  The executable files that should be installed into the `PATH`.
427
427
  */
428
428
  bin?:
429
- | string
430
- | Partial<Record<string, string>>;
429
+ | string
430
+ | Partial<Record<string, string>>;
431
431
 
432
432
  /**
433
433
  Filenames to put in place for the `man` program to find.
@@ -443,18 +443,18 @@ declare namespace PackageJson {
443
443
  Location for the code repository.
444
444
  */
445
445
  repository?:
446
- | string
447
- | {
448
- type: string;
449
- url: string;
446
+ | string
447
+ | {
448
+ type: string;
449
+ url: string;
450
450
 
451
- /**
451
+ /**
452
452
  Relative path to package.json if it is placed in non-root directory (for example if it is part of a monorepo).
453
453
 
454
454
  [Read more.](https://github.com/npm/rfcs/blob/latest/implemented/0010-monorepo-subdirectory-declaration.md)
455
455
  */
456
- directory?: string;
457
- };
456
+ directory?: string;
457
+ };
458
458
 
459
459
  /**
460
460
  Script commands that are run at various times in the lifecycle of the package. The key is the lifecycle event, and the value is the command to run at that point.
@@ -517,50 +517,50 @@ declare namespace PackageJson {
517
517
  Operating systems the module runs on.
518
518
  */
519
519
  os?: Array<LiteralUnion<
520
- | 'aix'
521
- | 'darwin'
522
- | 'freebsd'
523
- | 'linux'
524
- | 'openbsd'
525
- | 'sunos'
526
- | 'win32'
527
- | '!aix'
528
- | '!darwin'
529
- | '!freebsd'
530
- | '!linux'
531
- | '!openbsd'
532
- | '!sunos'
533
- | '!win32',
534
- string
520
+ | 'aix'
521
+ | 'darwin'
522
+ | 'freebsd'
523
+ | 'linux'
524
+ | 'openbsd'
525
+ | 'sunos'
526
+ | 'win32'
527
+ | '!aix'
528
+ | '!darwin'
529
+ | '!freebsd'
530
+ | '!linux'
531
+ | '!openbsd'
532
+ | '!sunos'
533
+ | '!win32',
534
+ string
535
535
  >>;
536
536
 
537
537
  /**
538
538
  CPU architectures the module runs on.
539
539
  */
540
540
  cpu?: Array<LiteralUnion<
541
- | 'arm'
542
- | 'arm64'
543
- | 'ia32'
544
- | 'mips'
545
- | 'mipsel'
546
- | 'ppc'
547
- | 'ppc64'
548
- | 's390'
549
- | 's390x'
550
- | 'x32'
551
- | 'x64'
552
- | '!arm'
553
- | '!arm64'
554
- | '!ia32'
555
- | '!mips'
556
- | '!mipsel'
557
- | '!ppc'
558
- | '!ppc64'
559
- | '!s390'
560
- | '!s390x'
561
- | '!x32'
562
- | '!x64',
563
- string
541
+ | 'arm'
542
+ | 'arm64'
543
+ | 'ia32'
544
+ | 'mips'
545
+ | 'mipsel'
546
+ | 'ppc'
547
+ | 'ppc64'
548
+ | 's390'
549
+ | 's390x'
550
+ | 'x32'
551
+ | 'x64'
552
+ | '!arm'
553
+ | '!arm64'
554
+ | '!ia32'
555
+ | '!mips'
556
+ | '!mipsel'
557
+ | '!ppc'
558
+ | '!ppc64'
559
+ | '!s390'
560
+ | '!s390x'
561
+ | '!x32'
562
+ | '!x64',
563
+ string
564
564
  >>;
565
565
 
566
566
  /**
@@ -583,20 +583,20 @@ declare namespace PackageJson {
583
583
  /**
584
584
  Describes and notifies consumers of a package's monetary support information.
585
585
 
586
- [Read more.](https://github.com/npm/rfcs/blob/latest/accepted/0017-add-funding-support.md)
586
+ [Read more.](https://github.com/npm/rfcs/blob/main/implemented/0017-add-funding-support.md)
587
587
  */
588
588
  funding?: string | {
589
589
  /**
590
590
  The type of funding.
591
591
  */
592
592
  type?: LiteralUnion<
593
- | 'github'
594
- | 'opencollective'
595
- | 'patreon'
596
- | 'individual'
597
- | 'foundation'
598
- | 'corporation',
599
- string
593
+ | 'github'
594
+ | 'opencollective'
595
+ | 'patreon'
596
+ | 'individual'
597
+ | 'foundation'
598
+ | 'corporation',
599
+ string
600
600
  >;
601
601
 
602
602
  /**
@@ -667,10 +667,10 @@ Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-j
667
667
  @category File
668
668
  */
669
669
  export type PackageJson =
670
- JsonObject &
671
- PackageJson.NodeJsStandard &
672
- PackageJson.PackageJsonStandard &
673
- PackageJson.NonStandardEntryPoints &
674
- PackageJson.TypeScriptConfiguration &
675
- PackageJson.YarnConfiguration &
676
- PackageJson.JSPMConfiguration;
670
+ JsonObject &
671
+ PackageJson.NodeJsStandard &
672
+ PackageJson.PackageJsonStandard &
673
+ PackageJson.NonStandardEntryPoints &
674
+ PackageJson.TypeScriptConfiguration &
675
+ PackageJson.YarnConfiguration &
676
+ PackageJson.JSPMConfiguration;
@@ -1,5 +1,5 @@
1
- import type {ApplyDefaultOptions, BuiltIns} from './internal';
2
- import type {IsNever} from './is-never';
1
+ import type {ApplyDefaultOptions, BuiltIns} from './internal/index.d.ts';
2
+ import type {IsNever} from './is-never.d.ts';
3
3
 
4
4
  /**
5
5
  @see {@link PartialDeep}
@@ -18,10 +18,10 @@ export type PartialDeepOptions = {
18
18
  - When set to `true`, elements of non-tuple arrays can be `undefined`.
19
19
  - When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
20
20
 
21
- @default true
21
+ @default false
22
22
 
23
23
  @example
24
- You can prevent `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}` as the second type argument:
24
+ You can allow `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}` as the second type argument:
25
25
 
26
26
  ```
27
27
  import type {PartialDeep} from 'type-fest';
@@ -30,10 +30,9 @@ export type PartialDeepOptions = {
30
30
  languages: string[];
31
31
  };
32
32
 
33
- declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
33
+ declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}>;
34
34
 
35
- partialSettings.languages = [undefined]; // Error
36
- partialSettings.languages = []; // Ok
35
+ partialSettings.languages = [undefined]; // OK
37
36
  ```
38
37
  */
39
38
  readonly allowUndefinedInNonTupleArrays?: boolean;
@@ -41,7 +40,7 @@ export type PartialDeepOptions = {
41
40
 
42
41
  type DefaultPartialDeepOptions = {
43
42
  recurseIntoArrays: false;
44
- allowUndefinedInNonTupleArrays: true;
43
+ allowUndefinedInNonTupleArrays: false;
45
44
  };
46
45
 
47
46
  /**
@@ -55,19 +54,19 @@ Use-cases:
55
54
  ```
56
55
  import type {PartialDeep} from 'type-fest';
57
56
 
58
- const settings: Settings = {
57
+ let settings = {
59
58
  textEditor: {
60
59
  fontSize: 14,
61
60
  fontColor: '#000000',
62
- fontWeight: 400
61
+ fontWeight: 400,
63
62
  },
64
63
  autocomplete: false,
65
- autosave: true
64
+ autosave: true,
66
65
  };
67
66
 
68
- const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
69
- return {...settings, ...savedSettings};
70
- }
67
+ const applySavedSettings = (savedSettings: PartialDeep<typeof settings>) => (
68
+ {...settings, ...savedSettings, textEditor: {...settings.textEditor, ...savedSettings.textEditor}}
69
+ );
71
70
 
72
71
  settings = applySavedSettings({textEditor: {fontWeight: 500}});
73
72
  ```
@@ -77,13 +76,15 @@ By default, this does not affect elements in array and tuple types. You can chan
77
76
  ```
78
77
  import type {PartialDeep} from 'type-fest';
79
78
 
80
- type Settings = {
81
- languages: string[];
82
- }
79
+ type Shape = {
80
+ dimensions: [number, number];
81
+ };
83
82
 
84
- const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
85
- languages: [undefined]
83
+ const partialShape: PartialDeep<Shape, {recurseIntoArrays: true}> = {
84
+ dimensions: [], // OK
86
85
  };
86
+
87
+ partialShape.dimensions = [15]; // OK
87
88
  ```
88
89
 
89
90
  @see {@link PartialDeepOptions}
@@ -147,5 +148,5 @@ type PartialObjectDeep<ObjectType extends object, Options extends Required<Parti
147
148
  (ObjectType extends (...arguments_: any) => unknown
148
149
  ? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType>
149
150
  : {}) & ({
150
- [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
151
- });
151
+ [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
152
+ });
@@ -1,6 +1,7 @@
1
- import type {IfUnknown} from './if-unknown';
2
- import type {ApplyDefaultOptions, BuiltIns, LiteralKeyOf} from './internal';
3
- import type {Merge} from './merge';
1
+ import type {If} from './if.d.ts';
2
+ import type {ApplyDefaultOptions, BuiltIns, LiteralKeyOf} from './internal/index.d.ts';
3
+ import type {IsUnknown} from './is-unknown.d.ts';
4
+ import type {Merge} from './merge.d.ts';
4
5
 
5
6
  /**
6
7
  @see PartialOnUndefinedDeep
@@ -55,7 +56,7 @@ export type PartialOnUndefinedDeep<T, Options extends PartialOnUndefinedDeepOpti
55
56
  _PartialOnUndefinedDeep<T, ApplyDefaultOptions<PartialOnUndefinedDeepOptions, DefaultPartialOnUndefinedDeepOptions, Options>>;
56
57
 
57
58
  type _PartialOnUndefinedDeep<T, Options extends Required<PartialOnUndefinedDeepOptions>> = T extends Record<any, any> | undefined
58
- ? {[KeyType in keyof T as undefined extends T[KeyType] ? IfUnknown<T[KeyType], never, KeyType> : never]?: PartialOnUndefinedDeepValue<T[KeyType], Options>} extends infer U // Make a partial type with all value types accepting undefined (and set them optional)
59
+ ? {[KeyType in keyof T as undefined extends T[KeyType] ? If<IsUnknown<T[KeyType]>, never, KeyType> : never]?: PartialOnUndefinedDeepValue<T[KeyType], Options>} extends infer U // Make a partial type with all value types accepting undefined (and set them optional)
59
60
  ? Merge<{[KeyType in keyof T as KeyType extends LiteralKeyOf<U> ? never : KeyType]: PartialOnUndefinedDeepValue<T[KeyType], Options>}, U> // Join all remaining keys not treated in U
60
61
  : never // Should not happen
61
62
  : T;
@@ -1,5 +1,5 @@
1
- import type {CamelCase, CamelCaseOptions, DefaultCamelCaseOptions} from './camel-case';
2
- import type {ApplyDefaultOptions} from './internal';
1
+ import type {CamelCase, CamelCaseOptions, DefaultCamelCaseOptions} from './camel-case.d.ts';
2
+ import type {ApplyDefaultOptions} from './internal/index.d.ts';
3
3
 
4
4
  /**
5
5
  Converts a string literal to pascal-case.
@@ -11,10 +11,11 @@ import type {PascalCase} from 'type-fest';
11
11
  // Simple
12
12
 
13
13
  const someVariable: PascalCase<'foo-bar'> = 'FooBar';
14
+ const preserveConsecutiveUppercase: PascalCase<'foo-BAR-baz', {preserveConsecutiveUppercase: true}> = 'FooBARBaz';
14
15
 
15
16
  // Advanced
16
17
 
17
- type PascalCaseProps<T> = {
18
+ type PascalCasedProperties<T> = {
18
19
  [K in keyof T as PascalCase<K>]: T[K]
19
20
  };
20
21
 
@@ -22,12 +23,18 @@ interface RawOptions {
22
23
  'dry-run': boolean;
23
24
  'full_family_name': string;
24
25
  foo: number;
25
- }
26
+ BAR: string;
27
+ QUZ_QUX: number;
28
+ 'OTHER-FIELD': boolean;
29
+ };
26
30
 
27
- const dbResult: CamelCasedProperties<ModelProps> = {
31
+ const dbResult: PascalCasedProperties<RawOptions> = {
28
32
  DryRun: true,
29
33
  FullFamilyName: 'bar.js',
30
- Foo: 123
34
+ Foo: 123,
35
+ Bar: 'foo',
36
+ QuzQux: 6,
37
+ OtherField: false,
31
38
  };
32
39
  ```
33
40
 
@@ -1,6 +1,6 @@
1
- import type {CamelCaseOptions, DefaultCamelCaseOptions} from './camel-case';
2
- import type {ApplyDefaultOptions} from './internal';
3
- import type {PascalCase} from './pascal-case';
1
+ import type {CamelCaseOptions, DefaultCamelCaseOptions} from './camel-case.d.ts';
2
+ import type {ApplyDefaultOptions} from './internal/index.d.ts';
3
+ import type {PascalCase} from './pascal-case.d.ts';
4
4
 
5
5
  /**
6
6
  Convert object properties to pascal case recursively.
@@ -40,6 +40,14 @@ const result: PascalCasedPropertiesDeep<UserWithFriends> = {
40
40
  },
41
41
  ],
42
42
  };
43
+
44
+ const preserveConsecutiveUppercase: PascalCasedPropertiesDeep<{fooBAR: {fooBARBiz: [{fooBARBaz: string}]}}, {preserveConsecutiveUppercase: true}> = {
45
+ FooBAR: {
46
+ FooBARBiz: [{
47
+ FooBARBaz: 'string',
48
+ }],
49
+ },
50
+ };
43
51
  ```
44
52
 
45
53
  @category Change case
@@ -1,6 +1,6 @@
1
- import type {CamelCaseOptions, DefaultCamelCaseOptions} from './camel-case';
2
- import type {ApplyDefaultOptions} from './internal';
3
- import type {PascalCase} from './pascal-case';
1
+ import type {CamelCaseOptions, DefaultCamelCaseOptions} from './camel-case.d.ts';
2
+ import type {ApplyDefaultOptions} from './internal/index.d.ts';
3
+ import type {PascalCase} from './pascal-case.d.ts';
4
4
 
5
5
  /**
6
6
  Convert object properties to pascal case but not recursively.
@@ -23,6 +23,10 @@ const result: PascalCasedProperties<User> = {
23
23
  UserId: 1,
24
24
  UserName: 'Tom',
25
25
  };
26
+
27
+ const preserveConsecutiveUppercase: PascalCasedProperties<{fooBAR: string}, {preserveConsecutiveUppercase: true}> = {
28
+ FooBAR: 'string',
29
+ };
26
30
  ```
27
31
 
28
32
  @category Change case