type-fest 3.13.1 → 4.0.0

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/index.d.ts CHANGED
@@ -16,13 +16,7 @@ export type {MergeExclusive} from './source/merge-exclusive';
16
16
  export type {RequireAtLeastOne} from './source/require-at-least-one';
17
17
  export type {RequireExactlyOne} from './source/require-exactly-one';
18
18
  export type {RequireAllOrNone} from './source/require-all-or-none';
19
- export type {
20
- OmitIndexSignature,
21
- /**
22
- @deprecated Renamed to {@link OmitIndexSignature}.
23
- */
24
- OmitIndexSignature as RemoveIndexSignature,
25
- } from './source/omit-index-signature';
19
+ export type {OmitIndexSignature} from './source/omit-index-signature';
26
20
  export type {PickIndexSignature} from './source/pick-index-signature';
27
21
  export type {PartialDeep, PartialDeepOptions} from './source/partial-deep';
28
22
  export type {RequiredDeep} from './source/required-deep';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "3.13.1",
3
+ "version": "4.0.0",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "types": "./index.d.ts",
14
14
  "engines": {
15
- "node": ">=14.16"
15
+ "node": ">=16"
16
16
  },
17
17
  "scripts": {
18
18
  "test": "xo && tsd && tsc && node script/test/source-files-extension.js"
@@ -38,7 +38,7 @@
38
38
  "expect-type": "^0.15.0",
39
39
  "tsd": "^0.28.1",
40
40
  "typescript": "^5.0.4",
41
- "xo": "^0.54.2"
41
+ "xo": "^0.55.0"
42
42
  },
43
43
  "xo": {
44
44
  "rules": {
package/readme.md CHANGED
@@ -64,7 +64,7 @@ PR welcome for additional commonly needed types and docs improvements. Read the
64
64
  npm install type-fest
65
65
  ```
66
66
 
67
- *Requires TypeScript >=4.7*
67
+ *Requires TypeScript >=5.1*
68
68
 
69
69
  ## Usage
70
70
 
@@ -1,16 +1,26 @@
1
1
  import type {JsonPrimitive, JsonValue} from './basic';
2
2
  import type {EmptyObject} from './empty-object';
3
3
  import type {UndefinedToOptional} from './internal';
4
+ import type {IsAny} from './is-any';
5
+ import type {IsNever} from './is-never';
4
6
  import type {NegativeInfinity, PositiveInfinity} from './numeric';
5
7
  import type {TypedArray} from './typed-array';
6
- import type {IsAny} from './is-any';
7
8
 
8
9
  // Note: The return value has to be `any` and not `unknown` so it can match `void`.
9
10
  type NotJsonable = ((...arguments_: any[]) => any) | undefined | symbol;
10
11
 
11
- type JsonifyTuple<T extends [unknown, ...unknown[]]> = {
12
- [Key in keyof T]: T[Key] extends NotJsonable ? null : Jsonify<T[Key]>;
13
- };
12
+ type FilterNonNever<T extends unknown[]> = T extends [infer F, ...infer R]
13
+ ? IsNever<F> extends true
14
+ ? FilterNonNever<R>
15
+ : [F, ...FilterNonNever<R>]
16
+ : IsNever<T[number]> extends true
17
+ ? []
18
+ : T;
19
+
20
+ // Handles tuples and arrays
21
+ type JsonifyList<T extends unknown[]> = T extends [infer F, ...infer R]
22
+ ? FilterNonNever<[Jsonify<F>, ...JsonifyList<R>]>
23
+ : Array<Jsonify<T[number]>>;
14
24
 
15
25
  type FilterJsonableKeys<T extends object> = {
16
26
  [Key in keyof T]: T[Key] extends NotJsonable ? never : Key;
@@ -107,7 +117,7 @@ export type Jsonify<T> = IsAny<T> extends true
107
117
  : T extends []
108
118
  ? []
109
119
  : T extends [unknown, ...unknown[]]
110
- ? JsonifyTuple<T>
120
+ ? JsonifyList<T>
111
121
  : T extends ReadonlyArray<infer U>
112
122
  ? Array<U extends NotJsonable ? null : Jsonify<U>>
113
123
  : T extends object
@@ -18,11 +18,11 @@ typeof lastOf(array);
18
18
  @category Array
19
19
  @category Template literal
20
20
  */
21
- export type LastArrayElement<ValueType extends readonly unknown[]> =
22
- ValueType extends readonly [infer ElementType]
23
- ? ElementType
24
- : ValueType extends readonly [infer _, ...infer Tail]
25
- ? LastArrayElement<Tail>
26
- : ValueType extends ReadonlyArray<infer ElementType>
27
- ? ElementType
21
+ export type LastArrayElement<Elements extends readonly unknown[]>
22
+ = number extends Elements['length']
23
+ ? Elements extends ReadonlyArray<infer Element>
24
+ ? Element
25
+ : never
26
+ : Elements extends readonly [...any, infer Target]
27
+ ? Target
28
28
  : never;
@@ -505,7 +505,7 @@ declare namespace PackageJson {
505
505
  Engines that this package runs on.
506
506
  */
507
507
  engines?: {
508
- [EngineName in 'npm' | 'node' | string]?: string; // eslint-disable-line @typescript-eslint/no-redundant-type-constituents
508
+ [EngineName in 'npm' | 'node' | string]?: string;
509
509
  };
510
510
 
511
511
  /**