type-fest 4.30.0 → 4.30.2

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.30.0",
3
+ "version": "4.30.2",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
@@ -64,6 +64,10 @@
64
64
  "multiline": true,
65
65
  "consistent": true
66
66
  }
67
+ ],
68
+ "import/consistent-type-specifier-style": [
69
+ "error",
70
+ "prefer-top-level"
67
71
  ]
68
72
  }
69
73
  },
package/readme.md CHANGED
@@ -194,7 +194,6 @@ Click the type names for complete docs.
194
194
  - [`TaggedUnion`](source/tagged-union.d.ts) - Create a union of types that share a common discriminant property.
195
195
  - [`IntRange`](source/int-range.d.ts) - Generate a union of numbers (includes the start and excludes the end).
196
196
  - [`IntClosedRange`](source/int-closed-range.d.ts) - Generate a union of numbers (includes the start and the end).
197
- - [`IntRange`](source/int-range.d.ts) - Generate a union of numbers.
198
197
  - [`ArrayIndices`](source/array-indices.d.ts) - Provides valid indices for a constant array or tuple.
199
198
  - [`ArrayValues`](source/array-values.d.ts) - Provides all values for a constant array or tuple.
200
199
  - [`ArraySplice`](source/array-splice.d.ts) - Creates a new array type by adding or removing elements at a specified index range in the original array.
@@ -13,7 +13,7 @@ function bundle(input: string, output: Arrayable<string>) {
13
13
  // …
14
14
 
15
15
  for (const output of outputList) {
16
- console.log(`write to: ${output}`);
16
+ console.log(`write to: ${output}`);
17
17
  }
18
18
  }
19
19
 
@@ -23,4 +23,7 @@ bundle('src/index.js', ['dist/index.cjs', 'dist/index.mjs']);
23
23
 
24
24
  @category Array
25
25
  */
26
- export type Arrayable<T> = T | readonly T[];
26
+ export type Arrayable<T> =
27
+ T
28
+ // TODO: Use `readonly T[]` when this issue is resolved: https://github.com/microsoft/TypeScript/issues/17002
29
+ | T[];
@@ -27,9 +27,11 @@ type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
27
27
  @category Object
28
28
  */
29
29
  export type SetOptional<BaseType, Keys extends keyof BaseType> =
30
- Simplify<
31
- // Pick just the keys that are readonly from the base type.
32
- Except<BaseType, Keys> &
33
- // Pick the keys that should be mutable from the base type and make them mutable.
34
- Partial<Pick<BaseType, Keys>>
35
- >;
30
+ BaseType extends unknown // To distribute `BaseType` when it's a union type.
31
+ ? Simplify<
32
+ // Pick just the keys that are readonly from the base type.
33
+ Except<BaseType, Keys> &
34
+ // Pick the keys that should be mutable from the base type and make them mutable.
35
+ Partial<Except<BaseType, Exclude<keyof BaseType, Keys>>>
36
+ >
37
+ : never;
@@ -33,6 +33,6 @@ export type SetReadonly<BaseType, Keys extends keyof BaseType> =
33
33
  BaseType extends unknown
34
34
  ? Simplify<
35
35
  Except<BaseType, Keys> &
36
- Readonly<Pick<BaseType, Keys>>
36
+ Readonly<Except<BaseType, Exclude<keyof BaseType, Keys>>>
37
37
  >
38
38
  : never;
@@ -35,6 +35,6 @@ export type SetRequired<BaseType, Keys extends keyof BaseType> =
35
35
  // Pick just the keys that are optional from the base type.
36
36
  Except<BaseType, Keys> &
37
37
  // Pick the keys that should be required from the base type and make them required.
38
- Required<Pick<BaseType, Keys>>
38
+ Required<Except<BaseType, Exclude<keyof BaseType, Keys>>>
39
39
  >
40
40
  : never;
@@ -1,5 +1,6 @@
1
1
  import type {NonRecursiveType, IsUnion} from './internal';
2
2
  import type {IsNever} from './is-never';
3
+ import type {Simplify} from './simplify';
3
4
  import type {UnknownArray} from './unknown-array';
4
5
 
5
6
  /**
@@ -63,21 +64,12 @@ function displayPetInfo(petInfo: SharedUnionFields<Cat | Dog>) {
63
64
  @category Union
64
65
  */
65
66
  export type SharedUnionFields<Union> =
66
- // If `Union` is not a union type, return `Union` directly.
67
- IsUnion<Union> extends false
68
- ? Union
69
- // `Union extends` will convert `Union`
70
- // to a [distributive conditionaltype](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
71
- // But this is not what we want, so we need to wrap `Union` with `[]` to prevent it.
72
- : [Union] extends [NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | UnknownArray]
73
- ? Union
74
- : [Union] extends [object]
75
- // `keyof Union` can extract the same key in union type, if there is no same key, return never.
76
- ? keyof Union extends infer Keys
77
- ? IsNever<Keys> extends false
78
- ? {
79
- [Key in keyof Union]: Union[Key]
80
- }
81
- : {}
82
- : Union
83
- : Union;
67
+ Extract<Union, NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | UnknownArray> extends infer SkippedMembers
68
+ ? Exclude<Union, SkippedMembers> extends infer RelevantMembers
69
+ ?
70
+ | SkippedMembers
71
+ | (IsNever<RelevantMembers> extends true
72
+ ? never
73
+ : Simplify<Pick<RelevantMembers, keyof RelevantMembers>>)
74
+ : never
75
+ : never;
@@ -18,6 +18,8 @@ UnionToIntersection<T extends any ? () => T : never> extends () => (infer R)
18
18
  /**
19
19
  Convert a union type into an unordered tuple type of its elements.
20
20
 
21
+ "Unordered" means the elements of the tuple are not guaranteed to be in the same order as in the union type. The arrangement can appear random and may change at any time.
22
+
21
23
  This can be useful when you have objects with a finite set of keys and want a type defining only the allowed keys, but do not want to repeat yourself.
22
24
 
23
25
  @example