type-fest 3.12.0 → 3.13.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.
package/index.d.ts CHANGED
@@ -79,7 +79,9 @@ export type {HasOptionalKeys} from './source/has-optional-keys';
79
79
  export type {RequiredKeysOf} from './source/required-keys-of';
80
80
  export type {HasRequiredKeys} from './source/has-required-keys';
81
81
  export type {ReadonlyKeysOf} from './source/readonly-keys-of';
82
+ export type {HasReadonlyKeys} from './source/has-readonly-keys';
82
83
  export type {WritableKeysOf} from './source/writable-keys-of';
84
+ export type {HasWritableKeys} from './source/has-writable-keys';
83
85
  export type {Spread} from './source/spread';
84
86
  export type {TupleToUnion} from './source/tuple-to-union';
85
87
  export type {IsEqual} from './source/is-equal';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "3.12.0",
3
+ "version": "3.13.1",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
package/readme.md CHANGED
@@ -144,8 +144,10 @@ Click the type names for complete docs.
144
144
  - [`HasOptionalKeys`](source/has-optional-keys.d.ts) - Create a `true`/`false` type depending on whether the given type has any optional fields.
145
145
  - [`RequiredKeysOf`](source/required-keys-of.d.ts) - Extract all required keys from the given type.
146
146
  - [`HasRequiredKeys`](source/has-required-keys.d.ts) - Create a `true`/`false` type depending on whether the given type has any required fields.
147
- - [`ReadonlyKeysOf`](source/readonly-keys-of.d.ts) - Extract all writable (non-readonly) keys from the given type.
148
- - [`WritableKeysOf`](source/writable-keys-of.d.ts) - Extract all readonly keys from the given type.
147
+ - [`ReadonlyKeysOf`](source/readonly-keys-of.d.ts) - Extract all readonly keys from the given type.
148
+ - [`HasReadonlyKeys`](source/has-readonly-keys.d.ts) - Create a `true`/`false` type depending on whether the given type has any readonly fields.
149
+ - [`WritableKeysOf`](source/writable-keys-of.d.ts) - Extract all writable (non-readonly) keys from the given type.
150
+ - [`HasWritableKeys`](source/has-writable-keys.d.ts) - Create a `true`/`false` type depending on whether the given type has any writable fields.
149
151
  - [`Spread`](source/spread.d.ts) - Mimic the type inferred by TypeScript when merging two objects or two arrays/tuples using the spread syntax.
150
152
  - [`IsEqual`](source/is-equal.d.ts) - Returns a boolean for whether the two given types are equal.
151
153
  - [`TaggedUnion`](source/tagged-union.d.ts) - Create a union of types that share a common discriminant property.
package/source/basic.d.ts CHANGED
@@ -3,7 +3,10 @@ Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe
3
3
 
4
4
  @category Class
5
5
  */
6
- export type Class<T, Arguments extends unknown[] = any[]> = Constructor<T, Arguments> & {prototype: T};
6
+ export type Class<T, Arguments extends unknown[] = any[]> = {
7
+ prototype: T;
8
+ new(...arguments_: Arguments): T;
9
+ };
7
10
 
8
11
  /**
9
12
  Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
@@ -16,8 +19,14 @@ export type Constructor<T, Arguments extends unknown[] = any[]> = new(...argumen
16
19
  Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/classes.html#abstract-classes).
17
20
 
18
21
  @category Class
22
+
23
+ @privateRemarks
24
+ We cannot use a `type` here because TypeScript throws: 'abstract' modifier cannot appear on a type member. (1070)
19
25
  */
20
- export type AbstractClass<T, Arguments extends unknown[] = any[]> = AbstractConstructor<T, Arguments> & {prototype: T};
26
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
27
+ export interface AbstractClass<T, Arguments extends unknown[] = any[]> extends AbstractConstructor<T, Arguments> {
28
+ prototype: T;
29
+ }
21
30
 
22
31
  /**
23
32
  Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html#abstract-construct-signatures) constructor.
@@ -0,0 +1,21 @@
1
+ import type {ReadonlyKeysOf} from './readonly-keys-of';
2
+
3
+ /**
4
+ Creates a type that represents `true` or `false` depending on whether the given type has any readonly fields.
5
+
6
+ This is useful when you want to create an API whose behavior depends on the presence or absence of readonly fields.
7
+
8
+ @example
9
+ ```
10
+ import type {HasReadonlyKeys, ReadonlyKeysOf} from 'type-fest';
11
+
12
+ type UpdateService<Entity extends object> = {
13
+ removeField: HasReadonlyKeys<Entity> extends true
14
+ ? (field: ReadonlyKeysOf<Entity>) => Promise<void>
15
+ : never
16
+ }
17
+ ```
18
+
19
+ @category Utilities
20
+ */
21
+ export type HasReadonlyKeys<BaseType extends object> = ReadonlyKeysOf<BaseType> extends never ? false : true;
@@ -0,0 +1,21 @@
1
+ import type {WritableKeysOf} from './writable-keys-of';
2
+
3
+ /**
4
+ Creates a type that represents `true` or `false` depending on whether the given type has any writable fields.
5
+
6
+ This is useful when you want to create an API whose behavior depends on the presence or absence of writable fields.
7
+
8
+ @example
9
+ ```
10
+ import type {HasWritableKeys, WritableKeysOf} from 'type-fest';
11
+
12
+ type UpdateService<Entity extends object> = {
13
+ removeField: HasWritableKeys<Entity> extends true
14
+ ? (field: WritableKeysOf<Entity>) => Promise<void>
15
+ : never
16
+ }
17
+ ```
18
+
19
+ @category Utilities
20
+ */
21
+ export type HasWritableKeys<BaseType extends object> = WritableKeysOf<BaseType> extends never ? false : true;
@@ -235,8 +235,8 @@ Needed to handle the case of a single call signature with properties.
235
235
  Multiple call signatures cannot currently be supported due to a TypeScript limitation.
236
236
  @see https://github.com/microsoft/TypeScript/issues/29732
237
237
  */
238
- export type HasMultipleCallSignatures<T extends (...arguments: any[]) => unknown> =
239
- T extends {(...arguments: infer A): unknown; (...arguments: any[]): unknown}
238
+ export type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
239
+ T extends {(...arguments_: infer A): unknown; (...arguments_: any[]): unknown}
240
240
  ? unknown[] extends A
241
241
  ? false
242
242
  : true
@@ -69,7 +69,7 @@ export type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends
69
69
  ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
70
70
  : T extends ReadonlySet<infer ItemType>
71
71
  ? PartialReadonlySetDeep<ItemType, Options>
72
- : T extends ((...arguments: any[]) => unknown)
72
+ : T extends ((...arguments_: any[]) => unknown)
73
73
  ? T | undefined
74
74
  : T extends object
75
75
  ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
@@ -55,7 +55,7 @@ export type PartialOnUndefinedDeep<T, Options extends PartialOnUndefinedDeepOpti
55
55
  /**
56
56
  Utility type to get the value type by key and recursively call `PartialOnUndefinedDeep` to transform sub-objects.
57
57
  */
58
- type PartialOnUndefinedDeepValue<T, Options extends PartialOnUndefinedDeepOptions> = T extends BuiltIns | ((...arguments: any[]) => unknown)
58
+ type PartialOnUndefinedDeepValue<T, Options extends PartialOnUndefinedDeepOptions> = T extends BuiltIns | ((...arguments_: any[]) => unknown)
59
59
  ? T
60
60
  : T extends ReadonlyArray<infer U> // Test if type is array or tuple
61
61
  ? Options['recurseIntoArrays'] extends true // Check if option is activated
@@ -38,12 +38,12 @@ Note that types containing overloaded functions are not made deeply readonly due
38
38
  */
39
39
  export type ReadonlyDeep<T> = T extends BuiltIns
40
40
  ? T
41
- : T extends (...arguments: any[]) => unknown
41
+ : T extends (...arguments_: any[]) => unknown
42
42
  ? {} extends ReadonlyObjectDeep<T>
43
43
  ? T
44
44
  : HasMultipleCallSignatures<T> extends true
45
45
  ? T
46
- : ((...arguments: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T>
46
+ : ((...arguments_: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T>
47
47
  : T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>>
48
48
  ? ReadonlyMapDeep<KeyType, ValueType>
49
49
  : T extends Readonly<ReadonlySet<infer ItemType>>
@@ -59,12 +59,12 @@ export type RequiredDeep<T, E extends ExcludeUndefined<T> = ExcludeUndefined<T>>
59
59
  ? WeakSet<RequiredDeep<ItemType>>
60
60
  : E extends Promise<infer ValueType>
61
61
  ? Promise<RequiredDeep<ValueType>>
62
- : E extends (...args: any[]) => unknown
62
+ : E extends (...arguments_: any[]) => unknown
63
63
  ? {} extends RequiredObjectDeep<E>
64
64
  ? E
65
65
  : HasMultipleCallSignatures<E> extends true
66
66
  ? E
67
- : ((...arguments: Parameters<E>) => ReturnType<E>) & RequiredObjectDeep<E>
67
+ : ((...arguments_: Parameters<E>) => ReturnType<E>) & RequiredObjectDeep<E>
68
68
  : E extends object
69
69
  ? E extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
70
70
  ? ItemType[] extends E // Test for arrays (non-tuples) specifically
@@ -51,7 +51,7 @@ export type Schema<ObjectType, ValueType> = ObjectType extends string
51
51
  ? ValueType
52
52
  : ObjectType extends unknown[]
53
53
  ? ValueType
54
- : ObjectType extends (...arguments: unknown[]) => unknown
54
+ : ObjectType extends (...arguments_: unknown[]) => unknown
55
55
  ? ValueType
56
56
  : ObjectType extends Date
57
57
  ? ValueType
@@ -32,12 +32,12 @@ Note that types containing overloaded functions are not made deeply writable due
32
32
  */
33
33
  export type WritableDeep<T> = T extends BuiltIns
34
34
  ? T
35
- : T extends (...arguments: any[]) => unknown
35
+ : T extends (...arguments_: any[]) => unknown
36
36
  ? {} extends WritableObjectDeep<T>
37
37
  ? T
38
38
  : HasMultipleCallSignatures<T> extends true
39
39
  ? T
40
- : ((...arguments: Parameters<T>) => ReturnType<T>) & WritableObjectDeep<T>
40
+ : ((...arguments_: Parameters<T>) => ReturnType<T>) & WritableObjectDeep<T>
41
41
  : T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>>
42
42
  ? WritableMapDeep<KeyType, ValueType>
43
43
  : T extends Readonly<ReadonlySet<infer ItemType>>