type-fest 4.8.1 → 4.8.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "4.8.1",
3
+ "version": "4.8.3",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
@@ -50,17 +50,15 @@ export type DelimiterCasedPropertiesDeep<
50
50
  Delimiter extends string,
51
51
  > = Value extends Function | Date | RegExp
52
52
  ? Value
53
- : Value extends string
54
- ? DelimiterCase<Value, Delimiter>
55
- : Value extends UnknownArray
56
- ? DelimiterCasedPropertiesArrayDeep<Value, Delimiter>
57
- : Value extends Set<infer U>
58
- ? Set<DelimiterCasedPropertiesDeep<U, Delimiter>> : {
59
- [K in keyof Value as DelimiterCase<
60
- K,
61
- Delimiter
62
- >]: DelimiterCasedPropertiesDeep<Value[K], Delimiter>;
63
- };
53
+ : Value extends UnknownArray
54
+ ? DelimiterCasedPropertiesArrayDeep<Value, Delimiter>
55
+ : Value extends Set<infer U>
56
+ ? Set<DelimiterCasedPropertiesDeep<U, Delimiter>> : {
57
+ [K in keyof Value as DelimiterCase<
58
+ K,
59
+ Delimiter
60
+ >]: DelimiterCasedPropertiesDeep<Value[K], Delimiter>;
61
+ };
64
62
 
65
63
  type DelimiterCasedPropertiesArrayDeep<Value extends UnknownArray, Delimiter extends string> =
66
64
  Value extends []
package/source/join.d.ts CHANGED
@@ -51,7 +51,7 @@ const path: Join<['hello' | undefined, 'world' | null], '.'> = ['hello', 'world'
51
51
  export type Join<
52
52
  Items extends readonly JoinableItem[],
53
53
  Delimiter extends string,
54
- > = Items extends []
54
+ > = Items extends readonly []
55
55
  ? ''
56
56
  : Items extends readonly [JoinableItem?]
57
57
  ? `${NullishCoalesce<Items[0], ''>}`
@@ -6,7 +6,7 @@ import type {IsNever} from './is-never';
6
6
  import type {IsUnknown} from './is-unknown';
7
7
  import type {NegativeInfinity, PositiveInfinity} from './numeric';
8
8
  import type {TypedArray} from './typed-array';
9
- import type {WritableDeep} from './writable-deep';
9
+ import type {UnknownArray} from './unknown-array';
10
10
 
11
11
  // Note: The return value has to be `any` and not `unknown` so it can match `void`.
12
12
  type NotJsonable = ((...arguments_: any[]) => any) | undefined | symbol;
@@ -14,9 +14,9 @@ type NotJsonable = ((...arguments_: any[]) => any) | undefined | symbol;
14
14
  type NeverToNull<T> = IsNever<T> extends true ? null : T;
15
15
 
16
16
  // Handles tuples and arrays
17
- type JsonifyList<T extends readonly unknown[]> = T extends []
17
+ type JsonifyList<T extends UnknownArray> = T extends readonly []
18
18
  ? []
19
- : T extends [infer F, ...infer R]
19
+ : T extends readonly [infer F, ...infer R]
20
20
  ? [NeverToNull<Jsonify<F>>, ...JsonifyList<R>]
21
21
  : IsUnknown<T[number]> extends true
22
22
  ? []
@@ -114,12 +114,8 @@ export type Jsonify<T> = IsAny<T> extends true
114
114
  ? Record<string, number>
115
115
  : T extends NotJsonable
116
116
  ? never // Non-JSONable type union was found not empty
117
- : T extends []
118
- ? []
119
- : T extends unknown[]
120
- ? JsonifyList<T>
121
- : T extends readonly unknown[]
122
- ? JsonifyList<WritableDeep<T>>
123
- : T extends object
124
- ? JsonifyObject<UndefinedToOptional<T>> // JsonifyObject recursive call for its children
125
- : never; // Otherwise any other non-object is removed
117
+ : T extends UnknownArray
118
+ ? JsonifyList<T>
119
+ : T extends object
120
+ ? JsonifyObject<UndefinedToOptional<T>> // JsonifyObject recursive call for its children
121
+ : never; // Otherwise any other non-object is removed
@@ -1,7 +1,6 @@
1
1
  import type {ConditionalSimplifyDeep} from './conditional-simplify';
2
2
  import type {OmitIndexSignature} from './omit-index-signature';
3
3
  import type {PickIndexSignature} from './pick-index-signature';
4
- import type {EnforceOptional} from './enforce-optional';
5
4
  import type {Merge} from './merge';
6
5
  import type {
7
6
  ArrayTail,
@@ -30,23 +29,28 @@ type MergeDeepRecordProperty<
30
29
 
31
30
  /**
32
31
  Walk through the union of the keys of the two objects and test in which object the properties are defined.
33
- - If the source does not contain the key, the value of the destination is returned.
34
- - If the source contains the key and the destination does not contain the key, the value of the source is returned.
35
- - If both contain the key, try to merge according to the chosen {@link MergeDeepOptions options} or return the source if unable to merge.
32
+ Rules:
33
+ 1. If the source does not contain the key, the value of the destination is returned.
34
+ 2. If the source contains the key and the destination does not contain the key, the value of the source is returned.
35
+ 3. If both contain the key, try to merge according to the chosen {@link MergeDeepOptions options} or return the source if unable to merge.
36
36
  */
37
37
  type DoMergeDeepRecord<
38
38
  Destination extends UnknownRecord,
39
39
  Source extends UnknownRecord,
40
40
  Options extends MergeDeepInternalOptions,
41
- > = EnforceOptional<{
42
- [Key in keyof Destination | keyof Source]: Key extends keyof Source
43
- ? Key extends keyof Destination
44
- ? MergeDeepRecordProperty<Destination[Key], Source[Key], Options>
45
- : Source[Key]
46
- : Key extends keyof Destination
47
- ? Destination[Key]
48
- : never;
49
- }>;
41
+ > =
42
+ // Case in rule 1: The destination contains the key but the source doesn't.
43
+ {
44
+ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
45
+ }
46
+ // Case in rule 2: The source contains the key but the destination doesn't.
47
+ & {
48
+ [Key in keyof Source as Key extends keyof Destination ? never : Key]: Source[Key];
49
+ }
50
+ // Case in rule 3: Both the source and the destination contain the key.
51
+ & {
52
+ [Key in keyof Source as Key extends keyof Destination ? Key : never]: MergeDeepRecordProperty<Destination[Key], Source[Key], Options>;
53
+ };
50
54
 
51
55
  /**
52
56
  Wrapper around {@link DoMergeDeepRecord} which preserves index signatures.
package/source/paths.d.ts CHANGED
@@ -78,7 +78,7 @@ open('listB.1'); // TypeError. Because listB only has one element.
78
78
  @category Array
79
79
  */
80
80
  export type Paths<T> =
81
- T extends NonRecursiveType
81
+ T extends NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>
82
82
  ? never
83
83
  : IsAny<T> extends true
84
84
  ? never
@@ -1,5 +1,4 @@
1
1
  import type {BuiltIns, HasMultipleCallSignatures} from './internal';
2
- import type {Writable} from './writable.js';
3
2
 
4
3
  /**
5
4
  Create a deeply mutable version of an `object`/`ReadonlyMap`/`ReadonlySet`/`ReadonlyArray` type. The inverse of `ReadonlyDeep<T>`. Use `Writable<T>` if you only need one level deep.