type-fest 2.19.0 → 3.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 +81 -73
- package/package.json +11 -10
- package/readme.md +25 -16
- package/source/async-return-type.d.ts +1 -3
- package/source/asyncify.d.ts +1 -2
- package/source/basic.d.ts +1 -1
- package/source/camel-case.d.ts +2 -2
- package/source/camel-cased-properties-deep.d.ts +5 -5
- package/source/camel-cased-properties.d.ts +3 -3
- package/source/conditional-except.d.ts +2 -2
- package/source/conditional-keys.d.ts +11 -11
- package/source/conditional-pick-deep.d.ts +102 -0
- package/source/conditional-pick.d.ts +2 -2
- package/source/conditional-simplify.d.ts +32 -0
- package/source/delimiter-case.d.ts +30 -24
- package/source/delimiter-cased-properties-deep.d.ts +6 -6
- package/source/delimiter-cased-properties.d.ts +2 -2
- package/source/empty-object.d.ts +46 -0
- package/source/enforce-optional.d.ts +47 -0
- package/source/entries.d.ts +3 -3
- package/source/entry.d.ts +3 -3
- package/source/exact.d.ts +4 -4
- package/source/fixed-length-array.d.ts +2 -2
- package/source/get.d.ts +52 -45
- package/source/has-optional-keys.d.ts +1 -1
- package/source/has-required-keys.d.ts +1 -1
- package/source/iterable-element.d.ts +4 -4
- package/source/join.d.ts +2 -2
- package/source/jsonify.d.ts +42 -20
- package/source/last-array-element.d.ts +4 -4
- package/source/literal-to-primitive.d.ts +12 -12
- package/source/merge.d.ts +33 -10
- package/source/observable-like.d.ts +3 -2
- package/source/{remove-index-signature.d.ts → omit-index-signature.d.ts} +14 -11
- package/source/package-json.d.ts +51 -27
- package/source/partial-deep.d.ts +29 -31
- package/source/partial-on-undefined-deep.d.ts +12 -12
- package/source/pascal-cased-properties-deep.d.ts +5 -5
- package/source/pascal-cased-properties.d.ts +2 -2
- package/source/pick-index-signature.d.ts +102 -0
- package/source/readonly-deep.d.ts +14 -16
- package/source/require-all-or-none.d.ts +1 -1
- package/source/require-at-least-one.d.ts +4 -4
- package/source/schema.d.ts +22 -22
- package/source/set-non-nullable.d.ts +4 -4
- package/source/set-optional.d.ts +4 -4
- package/source/set-required.d.ts +4 -4
- package/source/simplify.d.ts +1 -26
- package/source/split.d.ts +2 -2
- package/source/spread.d.ts +4 -4
- package/source/tsconfig-json.d.ts +16 -12
- package/source/tuple-to-union.d.ts +51 -0
- package/source/union-to-intersection.d.ts +3 -3
- package/source/writable.d.ts +4 -4
- package/source/mutable.d.ts +0 -5
- package/source/promise-value.d.ts +0 -29
package/index.d.ts
CHANGED
|
@@ -5,46 +5,53 @@ export * from './source/basic';
|
|
|
5
5
|
export * from './source/observable-like';
|
|
6
6
|
|
|
7
7
|
// Utilities
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {Writable} from './source/writable';
|
|
11
|
-
export {Merge} from './source/merge';
|
|
12
|
-
export {MergeExclusive} from './source/merge-exclusive';
|
|
13
|
-
export {RequireAtLeastOne} from './source/require-at-least-one';
|
|
14
|
-
export {RequireExactlyOne} from './source/require-exactly-one';
|
|
15
|
-
export {RequireAllOrNone} from './source/require-all-or-none';
|
|
16
|
-
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export {
|
|
36
|
-
export {
|
|
37
|
-
export {
|
|
38
|
-
export {
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
export {
|
|
42
|
-
export {
|
|
43
|
-
export {
|
|
44
|
-
export {
|
|
45
|
-
export {
|
|
46
|
-
export {
|
|
47
|
-
export {
|
|
8
|
+
export type {EmptyObject, IsEmptyObject} from './source/empty-object';
|
|
9
|
+
export type {Except} from './source/except';
|
|
10
|
+
export type {Writable} from './source/writable';
|
|
11
|
+
export type {Merge} from './source/merge';
|
|
12
|
+
export type {MergeExclusive} from './source/merge-exclusive';
|
|
13
|
+
export type {RequireAtLeastOne} from './source/require-at-least-one';
|
|
14
|
+
export type {RequireExactlyOne} from './source/require-exactly-one';
|
|
15
|
+
export type {RequireAllOrNone} from './source/require-all-or-none';
|
|
16
|
+
export type {
|
|
17
|
+
OmitIndexSignature,
|
|
18
|
+
/**
|
|
19
|
+
@deprecated Renamed to {@link OmitIndexSignature}.
|
|
20
|
+
*/
|
|
21
|
+
OmitIndexSignature as RemoveIndexSignature,
|
|
22
|
+
} from './source/omit-index-signature';
|
|
23
|
+
export type {PickIndexSignature} from './source/pick-index-signature';
|
|
24
|
+
export type {PartialDeep, PartialDeepOptions} from './source/partial-deep';
|
|
25
|
+
export type {PartialOnUndefinedDeep, PartialOnUndefinedDeepOptions} from './source/partial-on-undefined-deep';
|
|
26
|
+
export type {ReadonlyDeep} from './source/readonly-deep';
|
|
27
|
+
export type {LiteralUnion} from './source/literal-union';
|
|
28
|
+
export type {Promisable} from './source/promisable';
|
|
29
|
+
export type {Opaque, UnwrapOpaque} from './source/opaque';
|
|
30
|
+
export type {InvariantOf} from './source/invariant-of';
|
|
31
|
+
export type {SetOptional} from './source/set-optional';
|
|
32
|
+
export type {SetRequired} from './source/set-required';
|
|
33
|
+
export type {SetNonNullable} from './source/set-non-nullable';
|
|
34
|
+
export type {ValueOf} from './source/value-of';
|
|
35
|
+
export type {AsyncReturnType} from './source/async-return-type';
|
|
36
|
+
export type {ConditionalExcept} from './source/conditional-except';
|
|
37
|
+
export type {ConditionalKeys} from './source/conditional-keys';
|
|
38
|
+
export type {ConditionalPick} from './source/conditional-pick';
|
|
39
|
+
export type {ConditionalPickDeep, ConditionalPickDeepOptions} from './source/conditional-pick-deep';
|
|
40
|
+
export type {UnionToIntersection} from './source/union-to-intersection';
|
|
41
|
+
export type {Stringified} from './source/stringified';
|
|
42
|
+
export type {FixedLengthArray} from './source/fixed-length-array';
|
|
43
|
+
export type {MultidimensionalArray} from './source/multidimensional-array';
|
|
44
|
+
export type {MultidimensionalReadonlyArray} from './source/multidimensional-readonly-array';
|
|
45
|
+
export type {IterableElement} from './source/iterable-element';
|
|
46
|
+
export type {Entry} from './source/entry';
|
|
47
|
+
export type {Entries} from './source/entries';
|
|
48
|
+
export type {SetReturnType} from './source/set-return-type';
|
|
49
|
+
export type {Asyncify} from './source/asyncify';
|
|
50
|
+
export type {Simplify} from './source/simplify';
|
|
51
|
+
export type {Jsonify} from './source/jsonify';
|
|
52
|
+
export type {Schema} from './source/schema';
|
|
53
|
+
export type {LiteralToPrimitive} from './source/literal-to-primitive';
|
|
54
|
+
export type {
|
|
48
55
|
PositiveInfinity,
|
|
49
56
|
NegativeInfinity,
|
|
50
57
|
Finite,
|
|
@@ -56,40 +63,41 @@ export {
|
|
|
56
63
|
NegativeInteger,
|
|
57
64
|
NonNegativeInteger,
|
|
58
65
|
} from './source/numeric';
|
|
59
|
-
export {StringKeyOf} from './source/string-key-of';
|
|
60
|
-
export {Exact} from './source/exact';
|
|
61
|
-
export {ReadonlyTuple} from './source/readonly-tuple';
|
|
62
|
-
export {OptionalKeysOf} from './source/optional-keys-of';
|
|
63
|
-
export {HasOptionalKeys} from './source/has-optional-keys';
|
|
64
|
-
export {RequiredKeysOf} from './source/required-keys-of';
|
|
65
|
-
export {HasRequiredKeys} from './source/has-required-keys';
|
|
66
|
-
export {Spread} from './source/spread';
|
|
66
|
+
export type {StringKeyOf} from './source/string-key-of';
|
|
67
|
+
export type {Exact} from './source/exact';
|
|
68
|
+
export type {ReadonlyTuple} from './source/readonly-tuple';
|
|
69
|
+
export type {OptionalKeysOf} from './source/optional-keys-of';
|
|
70
|
+
export type {HasOptionalKeys} from './source/has-optional-keys';
|
|
71
|
+
export type {RequiredKeysOf} from './source/required-keys-of';
|
|
72
|
+
export type {HasRequiredKeys} from './source/has-required-keys';
|
|
73
|
+
export type {Spread} from './source/spread';
|
|
74
|
+
export type {TupleToUnion} from './source/tuple-to-union';
|
|
67
75
|
|
|
68
76
|
// Template literal types
|
|
69
|
-
export {CamelCase} from './source/camel-case';
|
|
70
|
-
export {CamelCasedProperties} from './source/camel-cased-properties';
|
|
71
|
-
export {CamelCasedPropertiesDeep} from './source/camel-cased-properties-deep';
|
|
72
|
-
export {KebabCase} from './source/kebab-case';
|
|
73
|
-
export {KebabCasedProperties} from './source/kebab-cased-properties';
|
|
74
|
-
export {KebabCasedPropertiesDeep} from './source/kebab-cased-properties-deep';
|
|
75
|
-
export {PascalCase} from './source/pascal-case';
|
|
76
|
-
export {PascalCasedProperties} from './source/pascal-cased-properties';
|
|
77
|
-
export {PascalCasedPropertiesDeep} from './source/pascal-cased-properties-deep';
|
|
78
|
-
export {SnakeCase} from './source/snake-case';
|
|
79
|
-
export {SnakeCasedProperties} from './source/snake-cased-properties';
|
|
80
|
-
export {SnakeCasedPropertiesDeep} from './source/snake-cased-properties-deep';
|
|
81
|
-
export {ScreamingSnakeCase} from './source/screaming-snake-case';
|
|
82
|
-
export {DelimiterCase} from './source/delimiter-case';
|
|
83
|
-
export {DelimiterCasedProperties} from './source/delimiter-cased-properties';
|
|
84
|
-
export {DelimiterCasedPropertiesDeep} from './source/delimiter-cased-properties-deep';
|
|
85
|
-
export {Join} from './source/join';
|
|
86
|
-
export {Split} from './source/split';
|
|
87
|
-
export {Trim} from './source/trim';
|
|
88
|
-
export {Replace} from './source/replace';
|
|
89
|
-
export {Includes} from './source/includes';
|
|
90
|
-
export {Get} from './source/get';
|
|
91
|
-
export {LastArrayElement} from './source/last-array-element';
|
|
77
|
+
export type {CamelCase} from './source/camel-case';
|
|
78
|
+
export type {CamelCasedProperties} from './source/camel-cased-properties';
|
|
79
|
+
export type {CamelCasedPropertiesDeep} from './source/camel-cased-properties-deep';
|
|
80
|
+
export type {KebabCase} from './source/kebab-case';
|
|
81
|
+
export type {KebabCasedProperties} from './source/kebab-cased-properties';
|
|
82
|
+
export type {KebabCasedPropertiesDeep} from './source/kebab-cased-properties-deep';
|
|
83
|
+
export type {PascalCase} from './source/pascal-case';
|
|
84
|
+
export type {PascalCasedProperties} from './source/pascal-cased-properties';
|
|
85
|
+
export type {PascalCasedPropertiesDeep} from './source/pascal-cased-properties-deep';
|
|
86
|
+
export type {SnakeCase} from './source/snake-case';
|
|
87
|
+
export type {SnakeCasedProperties} from './source/snake-cased-properties';
|
|
88
|
+
export type {SnakeCasedPropertiesDeep} from './source/snake-cased-properties-deep';
|
|
89
|
+
export type {ScreamingSnakeCase} from './source/screaming-snake-case';
|
|
90
|
+
export type {DelimiterCase} from './source/delimiter-case';
|
|
91
|
+
export type {DelimiterCasedProperties} from './source/delimiter-cased-properties';
|
|
92
|
+
export type {DelimiterCasedPropertiesDeep} from './source/delimiter-cased-properties-deep';
|
|
93
|
+
export type {Join} from './source/join';
|
|
94
|
+
export type {Split} from './source/split';
|
|
95
|
+
export type {Trim} from './source/trim';
|
|
96
|
+
export type {Replace} from './source/replace';
|
|
97
|
+
export type {Includes} from './source/includes';
|
|
98
|
+
export type {Get} from './source/get';
|
|
99
|
+
export type {LastArrayElement} from './source/last-array-element';
|
|
92
100
|
|
|
93
101
|
// Miscellaneous
|
|
94
|
-
export {PackageJson} from './source/package-json';
|
|
95
|
-
export {TsConfigJson} from './source/tsconfig-json';
|
|
102
|
+
export type {PackageJson} from './source/package-json';
|
|
103
|
+
export type {TsConfigJson} from './source/tsconfig-json';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-fest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.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",
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"email": "sindresorhus@gmail.com",
|
|
11
11
|
"url": "https://sindresorhus.com"
|
|
12
12
|
},
|
|
13
|
+
"types": "./index.d.ts",
|
|
13
14
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
15
|
+
"node": ">=14.16"
|
|
15
16
|
},
|
|
16
17
|
"scripts": {
|
|
17
18
|
"test": "xo && tsd && tsc && node script/test/source-files-extension.js"
|
|
@@ -29,21 +30,21 @@
|
|
|
29
30
|
"utilities",
|
|
30
31
|
"omit",
|
|
31
32
|
"merge",
|
|
32
|
-
"json"
|
|
33
|
+
"json",
|
|
34
|
+
"generics"
|
|
33
35
|
],
|
|
34
36
|
"devDependencies": {
|
|
35
37
|
"@sindresorhus/tsconfig": "~0.7.0",
|
|
36
|
-
"expect-type": "^0.
|
|
37
|
-
"tsd": "^0.
|
|
38
|
-
"typescript": "^4.
|
|
39
|
-
"xo": "^0.
|
|
38
|
+
"expect-type": "^0.14.2",
|
|
39
|
+
"tsd": "^0.24.1",
|
|
40
|
+
"typescript": "^4.8.3",
|
|
41
|
+
"xo": "^0.52.2"
|
|
40
42
|
},
|
|
41
|
-
"types": "./index.d.ts",
|
|
42
43
|
"xo": {
|
|
43
44
|
"rules": {
|
|
45
|
+
"@typescript-eslint/ban-ts-comment": "off",
|
|
44
46
|
"@typescript-eslint/ban-types": "off",
|
|
45
|
-
"@typescript-eslint/
|
|
46
|
-
"node/no-unsupported-features/es-builtins": "off",
|
|
47
|
+
"@typescript-eslint/naming-convention": "off",
|
|
47
48
|
"import/extensions": "off",
|
|
48
49
|
"@typescript-eslint/no-redeclare": "off",
|
|
49
50
|
"@typescript-eslint/no-confusing-void-expression": "off"
|
package/readme.md
CHANGED
|
@@ -68,6 +68,20 @@
|
|
|
68
68
|
</sub>
|
|
69
69
|
</div>
|
|
70
70
|
</a>
|
|
71
|
+
<br>
|
|
72
|
+
<br>
|
|
73
|
+
<a href="https://sizzy.co/?utm_campaign=github_repo&utm_source=github&utm_medium=referral&utm_content=type-fest&utm_term=sindre">
|
|
74
|
+
<div>
|
|
75
|
+
<img src="https://sindresorhus.com/assets/thanks/sizzy-logo.png" width="240" alt="Sizzy">
|
|
76
|
+
</div>
|
|
77
|
+
<div>
|
|
78
|
+
<sub>
|
|
79
|
+
<b>Before Sizzy:</b> web development is stressing you out, responsive design is hard, you have an overwhelming amount of opened tabs & apps.
|
|
80
|
+
<br>
|
|
81
|
+
<b>After Sizzy:</b> all the tools you need in one place, responsive design is a breeze, no more context switching.
|
|
82
|
+
</sub>
|
|
83
|
+
</div>
|
|
84
|
+
</a>
|
|
71
85
|
</p>
|
|
72
86
|
</div>
|
|
73
87
|
<br>
|
|
@@ -95,7 +109,7 @@ PR welcome for additional commonly needed types and docs improvements. Read the
|
|
|
95
109
|
npm install type-fest
|
|
96
110
|
```
|
|
97
111
|
|
|
98
|
-
*Requires TypeScript >=4.
|
|
112
|
+
*Requires TypeScript >=4.7*
|
|
99
113
|
|
|
100
114
|
## Usage
|
|
101
115
|
|
|
@@ -125,14 +139,17 @@ Click the type names for complete docs.
|
|
|
125
139
|
|
|
126
140
|
### Utilities
|
|
127
141
|
|
|
142
|
+
- [`EmptyObject`](source/empty-object.d.ts) - Represents a strictly empty plain object, the `{}` value.
|
|
143
|
+
- [`IsEmptyObject`](source/empty-object.d.ts) - Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
|
|
128
144
|
- [`Except`](source/except.d.ts) - Create a type from an object type without certain keys. This is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys).
|
|
129
|
-
- [`Writable`](source/writable.d.ts) - Create a type that strips `readonly` from all or some of an object's keys. The inverse of `Readonly<T>`.
|
|
145
|
+
- [`Writable`](source/writable.d.ts) - Create a type that strips `readonly` from all or some of an object's keys. The inverse of `Readonly<T>`.
|
|
130
146
|
- [`Merge`](source/merge.d.ts) - Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
131
147
|
- [`MergeExclusive`](source/merge-exclusive.d.ts) - Create a type that has mutually exclusive keys.
|
|
132
148
|
- [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given keys.
|
|
133
149
|
- [`RequireExactlyOne`](source/require-exactly-one.d.ts) - Create a type that requires exactly a single key of the given keys and disallows more.
|
|
134
150
|
- [`RequireAllOrNone`](source/require-all-or-none.d.ts) - Create a type that requires all of the given keys or none of the given keys.
|
|
135
|
-
- [`
|
|
151
|
+
- [`OmitIndexSignature`](source/omit-index-signature.d.ts) - Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
152
|
+
- [`PickIndexSignature`](source/pick-index-signature.d.ts) - Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
136
153
|
- [`PartialDeep`](source/partial-deep.d.ts) - Create a deeply optional version of another type. Use [`Partial<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) if you only need one level deep.
|
|
137
154
|
- [`PartialOnUndefinedDeep`](source/partial-on-undefined-deep.d.ts) - Create a deep version of another type where all keys accepting `undefined` type are set to optional.
|
|
138
155
|
- [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of an `object`/`Map`/`Set`/`Array` type. Use [`Readonly<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype) if you only need one level deep.
|
|
@@ -146,6 +163,7 @@ Click the type names for complete docs.
|
|
|
146
163
|
- [`ValueOf`](source/value-of.d.ts) - Create a union of the given object's values, and optionally specify which keys to get the values from.
|
|
147
164
|
- [`ConditionalKeys`](source/conditional-keys.d.ts) - Extract keys from a shape where values extend the given `Condition` type.
|
|
148
165
|
- [`ConditionalPick`](source/conditional-pick.d.ts) - Like `Pick` except it selects properties from a shape where the values extend the given `Condition` type.
|
|
166
|
+
- [`ConditionalPickDeep`](source/conditional-pick-deep.d.ts) - Like `ConditionalPick` except that it selects the properties deeply.
|
|
149
167
|
- [`ConditionalExcept`](source/conditional-except.d.ts) - Like `Omit` except it removes properties from a shape where the values extend the given `Condition` type.
|
|
150
168
|
- [`UnionToIntersection`](source/union-to-intersection.d.ts) - Convert a union type to an intersection type.
|
|
151
169
|
- [`LiteralToPrimitive`](source/literal-to-primitive.d.ts) - Convert a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) to the [primitive type](source/primitive.d.ts) it belongs to.
|
|
@@ -194,6 +212,7 @@ Click the type names for complete docs.
|
|
|
194
212
|
- [`MultidimensionalArray`](source/multidimensional-array.d.ts) - Create a type that represents a multidimensional array of the given type and dimensions.
|
|
195
213
|
- [`MultidimensionalReadonlyArray`](source/multidimensional-readonly-array.d.ts) - Create a type that represents a multidimensional readonly array of the given type and dimensions.
|
|
196
214
|
- [`ReadonlyTuple`](source/readonly-tuple.d.ts) - Create a type that represents a read-only tuple of the given type and length.
|
|
215
|
+
- [`TupleToUnion`](source/tuple-to-union.d.ts) - Convert a tuple into a union type of its elements.
|
|
197
216
|
|
|
198
217
|
### Numeric
|
|
199
218
|
|
|
@@ -230,7 +249,7 @@ Click the type names for complete docs.
|
|
|
230
249
|
### Miscellaneous
|
|
231
250
|
|
|
232
251
|
- [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). It also includes support for [TypeScript Declaration Files](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html) and [Yarn Workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces/).
|
|
233
|
-
- [`TsConfigJson`](source/tsconfig-json.d.ts) - Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html)
|
|
252
|
+
- [`TsConfigJson`](source/tsconfig-json.d.ts) - Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
|
|
234
253
|
|
|
235
254
|
## Declined types
|
|
236
255
|
|
|
@@ -251,6 +270,7 @@ Click the type names for complete docs.
|
|
|
251
270
|
|
|
252
271
|
- `PartialBy` - See [`SetOptional`](https://github.com/sindresorhus/type-fest/blob/main/source/set-optional.d.ts)
|
|
253
272
|
- `RecordDeep`- See [`Schema`](https://github.com/sindresorhus/type-fest/blob/main/source/schema.d.ts)
|
|
273
|
+
- `Mutable`- See [`Writable`](https://github.com/sindresorhus/type-fest/blob/main/source/writable.d.ts)
|
|
254
274
|
|
|
255
275
|
## Tips
|
|
256
276
|
|
|
@@ -887,19 +907,8 @@ You can find some examples in the [TypeScript docs](https://www.typescriptlang.o
|
|
|
887
907
|
- [Jarek Radosz](https://github.com/CvX)
|
|
888
908
|
- [Dimitri Benin](https://github.com/BendingBender)
|
|
889
909
|
- [Pelle Wessman](https://github.com/voxpelli)
|
|
910
|
+
- [Sébastien Mischler](https://github.com/skarab42)
|
|
890
911
|
|
|
891
912
|
## License
|
|
892
913
|
|
|
893
914
|
SPDX-License-Identifier: (MIT OR CC0-1.0)
|
|
894
|
-
|
|
895
|
-
---
|
|
896
|
-
|
|
897
|
-
<div align="center">
|
|
898
|
-
<b>
|
|
899
|
-
<a href="https://tidelift.com/subscription/pkg/npm-type-fest?utm_source=npm-type-fest&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
|
900
|
-
</b>
|
|
901
|
-
<br>
|
|
902
|
-
<sub>
|
|
903
|
-
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|
904
|
-
</sub>
|
|
905
|
-
</div>
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type {PromiseValue} from './promise-value';
|
|
2
|
-
|
|
3
1
|
type AsyncFunction = (...args: any[]) => Promise<unknown>;
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -22,4 +20,4 @@ asyncFunction().then(value => doSomething(value));
|
|
|
22
20
|
|
|
23
21
|
@category Async
|
|
24
22
|
*/
|
|
25
|
-
export type AsyncReturnType<Target extends AsyncFunction> =
|
|
23
|
+
export type AsyncReturnType<Target extends AsyncFunction> = Awaited<ReturnType<Target>>;
|
package/source/asyncify.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {PromiseValue} from './promise-value';
|
|
2
1
|
import type {SetReturnType} from './set-return-type';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -30,4 +29,4 @@ const getFooAsync: AsyncifiedFooGetter = (someArg) => {
|
|
|
30
29
|
|
|
31
30
|
@category Async
|
|
32
31
|
*/
|
|
33
|
-
export type Asyncify<Fn extends (...args: any[]) => any> = SetReturnType<Fn, Promise<
|
|
32
|
+
export type Asyncify<Fn extends (...args: any[]) => any> = SetReturnType<Fn, Promise<Awaited<ReturnType<Fn>>>>;
|
package/source/basic.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ This type can be useful to enforce some input to be JSON-compatible or as a supe
|
|
|
19
19
|
|
|
20
20
|
@category JSON
|
|
21
21
|
*/
|
|
22
|
-
export type JsonObject = {[Key in string]?: JsonValue};
|
|
22
|
+
export type JsonObject = {[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined};
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
Matches a JSON array.
|
package/source/camel-case.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ type InnerCamelCaseStringArray<Parts extends readonly any[], PreviousPart> =
|
|
|
13
13
|
? FirstPart extends undefined
|
|
14
14
|
? ''
|
|
15
15
|
: FirstPart extends ''
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
? InnerCamelCaseStringArray<RemainingParts, PreviousPart>
|
|
17
|
+
: `${PreviousPart extends '' ? FirstPart : Capitalize<FirstPart>}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`
|
|
18
18
|
: '';
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -47,8 +47,8 @@ const result: CamelCasedPropertiesDeep<UserWithFriends> = {
|
|
|
47
47
|
export type CamelCasedPropertiesDeep<Value> = Value extends Function
|
|
48
48
|
? Value
|
|
49
49
|
: Value extends Array<infer U>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
? Array<CamelCasedPropertiesDeep<U>>
|
|
51
|
+
: Value extends Set<infer U>
|
|
52
|
+
? Set<CamelCasedPropertiesDeep<U>> : {
|
|
53
|
+
[K in keyof Value as CamelCase<K>]: CamelCasedPropertiesDeep<Value[K]>;
|
|
54
|
+
};
|
|
@@ -31,17 +31,17 @@ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
|
|
|
31
31
|
@category Object
|
|
32
32
|
*/
|
|
33
33
|
export type ConditionalKeys<Base, Condition> = NonNullable<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
|
|
35
|
+
{
|
|
36
|
+
// Map through all the keys of the given base type.
|
|
37
|
+
[Key in keyof Base]:
|
|
38
|
+
// Pick only keys with types extending the given `Condition` type.
|
|
39
|
+
Base[Key] extends Condition
|
|
40
|
+
// Retain this key since the condition passes.
|
|
41
|
+
? Key
|
|
42
|
+
// Discard this key since the condition fails.
|
|
43
|
+
: never;
|
|
44
44
|
|
|
45
45
|
// Convert the produced object into a union type of the keys which passed the conditional test.
|
|
46
|
-
|
|
46
|
+
}[keyof Base]
|
|
47
47
|
>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type {Opaque} from './opaque';
|
|
2
|
+
import type {IsEqual} from './internal';
|
|
3
|
+
import type {ConditionalExcept} from './conditional-except';
|
|
4
|
+
import type {ConditionalSimplifyDeep} from './conditional-simplify';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
Used to mark properties that should be excluded.
|
|
8
|
+
*/
|
|
9
|
+
type ConditionalPickDeepSymbol = Opaque<symbol, 'conditional-pick-deep-symbol'>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
Assert the condition according to the {@link ConditionalPickDeepOptions.condition|condition} option.
|
|
13
|
+
*/
|
|
14
|
+
type AssertCondition<Type, Condition, Options extends ConditionalPickDeepOptions> = Options['condition'] extends 'equality'
|
|
15
|
+
? IsEqual<Type, Condition>
|
|
16
|
+
: Type extends Condition
|
|
17
|
+
? true
|
|
18
|
+
: false;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
ConditionalPickDeep options.
|
|
22
|
+
|
|
23
|
+
@see ConditionalPickDeep
|
|
24
|
+
*/
|
|
25
|
+
export type ConditionalPickDeepOptions = {
|
|
26
|
+
/**
|
|
27
|
+
The condition assertion mode.
|
|
28
|
+
|
|
29
|
+
@default 'extends'
|
|
30
|
+
*/
|
|
31
|
+
condition?: 'extends' | 'equality';
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
Pick keys recursively from the shape that matches the given condition.
|
|
36
|
+
|
|
37
|
+
@see ConditionalPick
|
|
38
|
+
|
|
39
|
+
@example
|
|
40
|
+
```
|
|
41
|
+
import type {ConditionalPickDeep} from 'type-fest';
|
|
42
|
+
|
|
43
|
+
interface Example {
|
|
44
|
+
a: string;
|
|
45
|
+
b: string | boolean;
|
|
46
|
+
c: {
|
|
47
|
+
d: string;
|
|
48
|
+
e: {
|
|
49
|
+
f?: string;
|
|
50
|
+
g?: boolean;
|
|
51
|
+
h: string | boolean;
|
|
52
|
+
i: boolean | bigint;
|
|
53
|
+
};
|
|
54
|
+
j: boolean;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type StringPick = ConditionalPickDeep<Example, string>;
|
|
59
|
+
//=> {a: string; c: {d: string}}
|
|
60
|
+
|
|
61
|
+
type StringPickOptional = ConditionalPickDeep<Example, string | undefined>;
|
|
62
|
+
//=> {a: string; c: {d: string; e: {f?: string}}}
|
|
63
|
+
|
|
64
|
+
type StringPickOptionalOnly = ConditionalPickDeep<Example, string | undefined, {condition: 'equality'}>;
|
|
65
|
+
//=> {c: {e: {f?: string}}}
|
|
66
|
+
|
|
67
|
+
type BooleanPick = ConditionalPickDeep<Example, boolean | undefined>;
|
|
68
|
+
//=> {c: {e: {g?: boolean}; j: boolean}}
|
|
69
|
+
|
|
70
|
+
type NumberPick = ConditionalPickDeep<Example, number>;
|
|
71
|
+
//=> {}
|
|
72
|
+
|
|
73
|
+
type StringOrBooleanPick = ConditionalPickDeep<Example, string | boolean>;
|
|
74
|
+
//=> {
|
|
75
|
+
// a: string;
|
|
76
|
+
// b: string | boolean;
|
|
77
|
+
// c: {
|
|
78
|
+
// d: string;
|
|
79
|
+
// e: {
|
|
80
|
+
// h: string | boolean
|
|
81
|
+
// };
|
|
82
|
+
// j: boolean;
|
|
83
|
+
// };
|
|
84
|
+
// }
|
|
85
|
+
|
|
86
|
+
type StringOrBooleanPickOnly = ConditionalPickDeep<Example, string | boolean, {condition: 'equality'}>;
|
|
87
|
+
//=> {b: string | boolean; c: {e: {h: string | boolean}}}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
@category Object
|
|
91
|
+
*/
|
|
92
|
+
export type ConditionalPickDeep<
|
|
93
|
+
Type,
|
|
94
|
+
Condition,
|
|
95
|
+
Options extends ConditionalPickDeepOptions = {},
|
|
96
|
+
> = ConditionalSimplifyDeep<ConditionalExcept<{
|
|
97
|
+
[Key in keyof Type]: AssertCondition<Type[Key], Condition, Options> extends true
|
|
98
|
+
? Type[Key]
|
|
99
|
+
: Type[Key] extends object
|
|
100
|
+
? ConditionalPickDeep<Type[Key], Condition, Options>
|
|
101
|
+
: ConditionalPickDeepSymbol;
|
|
102
|
+
}, (ConditionalPickDeepSymbol | undefined) | Record<PropertyKey, never>>>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Simplifies a type while including and/or excluding certain types from being simplified. Useful to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
3
|
+
|
|
4
|
+
This type is **experimental** and was introduced as a result of this {@link https://github.com/sindresorhus/type-fest/issues/436 issue}. It should be used with caution.
|
|
5
|
+
|
|
6
|
+
@internal
|
|
7
|
+
@experimental
|
|
8
|
+
@see Simplify
|
|
9
|
+
@category Object
|
|
10
|
+
*/
|
|
11
|
+
export type ConditionalSimplify<Type, ExcludeType = never, IncludeType = unknown> = Type extends ExcludeType
|
|
12
|
+
? Type
|
|
13
|
+
: Type extends IncludeType
|
|
14
|
+
? {[TypeKey in keyof Type]: Type[TypeKey]}
|
|
15
|
+
: Type;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
Recursively simplifies a type while including and/or excluding certain types from being simplified.
|
|
19
|
+
|
|
20
|
+
This type is **experimental** and was introduced as a result of this {@link https://github.com/sindresorhus/type-fest/issues/436 issue}. It should be used with caution.
|
|
21
|
+
|
|
22
|
+
See {@link ConditionalSimplify} for usages and examples.
|
|
23
|
+
|
|
24
|
+
@internal
|
|
25
|
+
@experimental
|
|
26
|
+
@category Object
|
|
27
|
+
*/
|
|
28
|
+
export type ConditionalSimplifyDeep<Type, ExcludeType = never, IncludeType = unknown> = Type extends ExcludeType
|
|
29
|
+
? Type
|
|
30
|
+
: Type extends IncludeType
|
|
31
|
+
? {[TypeKey in keyof Type]: ConditionalSimplifyDeep<Type[TypeKey], ExcludeType, IncludeType>}
|
|
32
|
+
: Type;
|