type-fest 5.4.4 → 5.6.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 +10 -0
- package/package.json +6 -4
- package/readme.md +83 -58
- package/source/absolute.d.ts +52 -0
- package/source/all-extend.d.ts +5 -6
- package/source/all-union-fields.d.ts +18 -18
- package/source/and-all.d.ts +76 -0
- package/source/and.d.ts +4 -3
- package/source/array-length.d.ts +36 -0
- package/source/array-splice.d.ts +26 -26
- package/source/camel-case.d.ts +38 -5
- package/source/camel-cased-properties-deep.d.ts +11 -4
- package/source/camel-cased-properties.d.ts +5 -1
- package/source/conditional-pick-deep.d.ts +5 -3
- package/source/conditional-pick.d.ts +6 -4
- package/source/delimiter-case.d.ts +1 -0
- package/source/delimiter-cased-properties-deep.d.ts +8 -1
- package/source/delimiter-cased-properties.d.ts +5 -1
- package/source/empty-object.d.ts +1 -1
- package/source/entries.d.ts +1 -1
- package/source/entry.d.ts +1 -1
- package/source/exclude-exactly.d.ts +57 -0
- package/source/get.d.ts +1 -1
- package/source/greater-than-or-equal.d.ts +34 -1
- package/source/greater-than.d.ts +37 -3
- package/source/has-optional-keys.d.ts +1 -1
- package/source/has-readonly-keys.d.ts +1 -1
- package/source/has-required-keys.d.ts +1 -1
- package/source/has-writable-keys.d.ts +1 -1
- package/source/int-closed-range.d.ts +1 -3
- package/source/int-range.d.ts +3 -5
- package/source/internal/array.d.ts +7 -14
- package/source/internal/keys.d.ts +9 -9
- package/source/internal/numeric.d.ts +13 -23
- package/source/internal/tuple.d.ts +3 -3
- package/source/internal/type.d.ts +1 -0
- package/source/is-equal.d.ts +0 -1
- package/source/is-integer.d.ts +8 -8
- package/source/is-literal.d.ts +5 -5
- package/source/is-union.d.ts +12 -12
- package/source/iterable-element.d.ts +5 -5
- package/source/jsonify.d.ts +4 -4
- package/source/kebab-case.d.ts +1 -0
- package/source/kebab-cased-properties-deep.d.ts +7 -0
- package/source/kebab-cased-properties.d.ts +5 -1
- package/source/keys-of-union.d.ts +2 -2
- package/source/less-than-or-equal.d.ts +40 -4
- package/source/less-than.d.ts +35 -3
- package/source/literal-to-primitive.d.ts +1 -1
- package/source/literal-union.d.ts +1 -1
- package/source/merge-exclusive.d.ts +3 -3
- package/source/merge.d.ts +25 -0
- package/source/multidimensional-array.d.ts +1 -1
- package/source/multidimensional-readonly-array.d.ts +1 -1
- package/source/non-nullable-deep.d.ts +102 -0
- package/source/numeric.d.ts +3 -3
- package/source/omit-deep.d.ts +22 -23
- package/source/optional.d.ts +31 -0
- package/source/or-all.d.ts +73 -0
- package/source/or.d.ts +4 -11
- package/source/package-json.d.ts +7 -7
- package/source/partial-deep.d.ts +3 -1
- package/source/pascal-case.d.ts +1 -0
- package/source/pascal-cased-properties-deep.d.ts +7 -0
- package/source/pascal-cased-properties.d.ts +5 -1
- package/source/pick-deep.d.ts +8 -21
- package/source/readonly-deep.d.ts +5 -3
- package/source/remove-prefix.d.ts +15 -15
- package/source/replace.d.ts +2 -2
- package/source/require-all-or-none.d.ts +1 -1
- package/source/require-at-least-one.d.ts +5 -7
- package/source/require-exactly-one.d.ts +3 -3
- package/source/require-one-or-none.d.ts +1 -1
- package/source/required-deep.d.ts +3 -1
- package/source/screaming-snake-case.d.ts +1 -0
- package/source/set-non-nullable-deep.d.ts +6 -3
- package/source/set-non-nullable.d.ts +4 -11
- package/source/set-optional.d.ts +6 -10
- package/source/set-parameter-type.d.ts +2 -2
- package/source/set-readonly.d.ts +4 -8
- package/source/set-required-deep.d.ts +1 -1
- package/source/set-required.d.ts +4 -8
- package/source/shared-union-fields-deep.d.ts +1 -1
- package/source/shared-union-fields.d.ts +9 -9
- package/source/snake-case.d.ts +1 -0
- package/source/snake-cased-properties-deep.d.ts +7 -0
- package/source/snake-cased-properties.d.ts +5 -1
- package/source/some-extend.d.ts +113 -0
- package/source/spread.d.ts +1 -5
- package/source/subtract.d.ts +4 -3
- package/source/sum.d.ts +5 -4
- package/source/tagged.d.ts +5 -7
- package/source/tsconfig-json.d.ts +39 -7
- package/source/union-length.d.ts +27 -0
- package/source/union-member.d.ts +65 -0
- package/source/union-to-intersection.d.ts +1 -1
- package/source/union-to-tuple.d.ts +10 -19
- package/source/words.d.ts +30 -4
- package/source/writable.d.ts +15 -19
- package/source/xor.d.ts +1 -1
package/index.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export type {ReadonlyDeep} from './source/readonly-deep.d.ts';
|
|
|
43
43
|
export type {LiteralUnion} from './source/literal-union.d.ts';
|
|
44
44
|
export type {Promisable} from './source/promisable.d.ts';
|
|
45
45
|
export type {Arrayable} from './source/arrayable.d.ts';
|
|
46
|
+
export type {Optional} from './source/optional.d.ts';
|
|
46
47
|
export type {Opaque, UnwrapOpaque, Tagged, GetTagMetadata, UnwrapTagged} from './source/tagged.d.ts';
|
|
47
48
|
export type {InvariantOf} from './source/invariant-of.d.ts';
|
|
48
49
|
export type {SetOptional} from './source/set-optional.d.ts';
|
|
@@ -51,6 +52,7 @@ export type {SetRequired} from './source/set-required.d.ts';
|
|
|
51
52
|
export type {SetRequiredDeep} from './source/set-required-deep.d.ts';
|
|
52
53
|
export type {SetNonNullable} from './source/set-non-nullable.d.ts';
|
|
53
54
|
export type {SetNonNullableDeep} from './source/set-non-nullable-deep.d.ts';
|
|
55
|
+
export type {NonNullableDeep} from './source/non-nullable-deep.d.ts';
|
|
54
56
|
export type {ValueOf} from './source/value-of.d.ts';
|
|
55
57
|
export type {AsyncReturnType} from './source/async-return-type.d.ts';
|
|
56
58
|
export type {ConditionalExcept} from './source/conditional-except.d.ts';
|
|
@@ -144,6 +146,7 @@ export type {ArraySlice} from './source/array-slice.d.ts';
|
|
|
144
146
|
export type {ArraySplice} from './source/array-splice.d.ts';
|
|
145
147
|
export type {ArrayTail} from './source/array-tail.d.ts';
|
|
146
148
|
export type {ArrayElement} from './source/array-element.d.ts';
|
|
149
|
+
export type {ArrayLength} from './source/array-length.d.ts';
|
|
147
150
|
export type {SetFieldType, SetFieldTypeOptions} from './source/set-field-type.d.ts';
|
|
148
151
|
export type {Paths, PathsOptions} from './source/paths.d.ts';
|
|
149
152
|
export type {AllUnionFields} from './source/all-union-fields.d.ts';
|
|
@@ -153,9 +156,12 @@ export type {IsNull} from './source/is-null.d.ts';
|
|
|
153
156
|
export type {IfNull} from './source/if-null.d.ts';
|
|
154
157
|
export type {IsUndefined} from './source/is-undefined.d.ts';
|
|
155
158
|
export type {And} from './source/and.d.ts';
|
|
159
|
+
export type {AndAll} from './source/and-all.d.ts';
|
|
156
160
|
export type {Or} from './source/or.d.ts';
|
|
161
|
+
export type {OrAll} from './source/or-all.d.ts';
|
|
157
162
|
export type {Xor} from './source/xor.d.ts';
|
|
158
163
|
export type {AllExtend, AllExtendOptions} from './source/all-extend.d.ts';
|
|
164
|
+
export type {SomeExtend, SomeExtendOptions} from './source/some-extend.d.ts';
|
|
159
165
|
export type {NonEmptyTuple} from './source/non-empty-tuple.d.ts';
|
|
160
166
|
export type {FindGlobalInstanceType, FindGlobalType} from './source/find-global-type.d.ts';
|
|
161
167
|
export type {If} from './source/if.d.ts';
|
|
@@ -167,6 +173,9 @@ export type {IsNullable} from './source/is-nullable.d.ts';
|
|
|
167
173
|
export type {TupleOf} from './source/tuple-of.d.ts';
|
|
168
174
|
export type {ExclusifyUnion} from './source/exclusify-union.d.ts';
|
|
169
175
|
export type {ArrayReverse} from './source/array-reverse.d.ts';
|
|
176
|
+
export type {UnionMember} from './source/union-member.d.ts';
|
|
177
|
+
export type {Absolute} from './source/absolute.d.ts';
|
|
178
|
+
export type {UnionLength} from './source/union-length.d.ts';
|
|
170
179
|
|
|
171
180
|
// Template literal types
|
|
172
181
|
export type {CamelCase, CamelCaseOptions} from './source/camel-case.d.ts';
|
|
@@ -207,5 +216,6 @@ export type {TsConfigJson} from './source/tsconfig-json.d.ts';
|
|
|
207
216
|
export type {ExtendsStrict} from './source/extends-strict.d.ts';
|
|
208
217
|
export type {ExtractStrict} from './source/extract-strict.d.ts';
|
|
209
218
|
export type {ExcludeStrict} from './source/exclude-strict.d.ts';
|
|
219
|
+
export type {ExcludeExactly} from './source/exclude-exactly.d.ts';
|
|
210
220
|
|
|
211
221
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-fest",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "A collection of essential TypeScript types",
|
|
5
5
|
"license": "(MIT OR CC0-1.0)",
|
|
6
6
|
"repository": "sindresorhus/type-fest",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test:tsc": "node --max-old-space-size=6144 ./node_modules/.bin/tsc",
|
|
29
29
|
"test:tsd": "node --max-old-space-size=6144 ./node_modules/.bin/tsd",
|
|
30
|
-
"test:xo": "node --max-old-space-size=6144 ./node_modules/.bin/xo --ignores=lint-processors/fixtures/**/*.d.ts",
|
|
30
|
+
"test:xo": "node --max-old-space-size=6144 ./node_modules/.bin/xo --ignores=lint-processors/fixtures/**/*.d.ts '**/*.{js,ts,md}'",
|
|
31
31
|
"test:linter": "node --test",
|
|
32
32
|
"test": "run-p test:*"
|
|
33
33
|
},
|
|
@@ -53,17 +53,19 @@
|
|
|
53
53
|
"tagged-tag": "^1.0.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
+
"@eslint/markdown": "^8.0.1",
|
|
56
57
|
"@sindresorhus/tsconfig": "^8.0.1",
|
|
58
|
+
"@types/node": "^25.5.0",
|
|
57
59
|
"@typescript-eslint/parser": "^8.44.0",
|
|
58
|
-
"eslint": "^9.35.0",
|
|
59
60
|
"@typescript/vfs": "^1.6.1",
|
|
60
61
|
"dedent": "^1.7.0",
|
|
62
|
+
"eslint": "^10.1.0",
|
|
61
63
|
"expect-type": "^1.2.2",
|
|
62
64
|
"npm-run-all2": "^8.0.4",
|
|
63
65
|
"tsd": "^0.33.0",
|
|
64
66
|
"typescript": "^5.9.2",
|
|
65
67
|
"typescript-eslint": "^8.47.0",
|
|
66
|
-
"xo": "^
|
|
68
|
+
"xo": "^2.0.2"
|
|
67
69
|
},
|
|
68
70
|
"tsd": {
|
|
69
71
|
"compilerOptions": {
|
package/readme.md
CHANGED
|
@@ -29,6 +29,17 @@
|
|
|
29
29
|
<sup>An open-source framework that supports any programming language, cloud provider, or deployment automation tool.</sup>
|
|
30
30
|
</div>
|
|
31
31
|
</a>
|
|
32
|
+
<br>
|
|
33
|
+
<br>
|
|
34
|
+
<a href="https://circleback.ai?utm_source=sindresorhus&utm_medium=sponsorship&utm_campaign=awesome-list&utm_id=type-fest">
|
|
35
|
+
<div>
|
|
36
|
+
<img width="300" src="https://sindresorhus.com/assets/thanks/circleback-logo.png?x" alt="Circleback logo">
|
|
37
|
+
</div>
|
|
38
|
+
<b>Get the most out of every conversation.</b>
|
|
39
|
+
<div>
|
|
40
|
+
<sup>AI-powered meeting notes, automations, and search. Give AI agents the context they need to get things done.</sup>
|
|
41
|
+
</div>
|
|
42
|
+
</a>
|
|
32
43
|
</p>
|
|
33
44
|
</div>
|
|
34
45
|
<br>
|
|
@@ -102,51 +113,52 @@ Click the type names for complete docs.
|
|
|
102
113
|
- [`UnknownArray`](source/unknown-array.d.ts) - Represents an array with `unknown` value.
|
|
103
114
|
- [`UnknownMap`](source/unknown-map.d.ts) - Represents a map with `unknown` key and value.
|
|
104
115
|
- [`UnknownSet`](source/unknown-set.d.ts) - Represents a set with `unknown` value.
|
|
105
|
-
- [`Except`](source/except.d.ts) - Create a type from an object type without certain keys.
|
|
116
|
+
- [`Except`](source/except.d.ts) - Create a type from an object type without certain keys.
|
|
106
117
|
- [`Writable`](source/writable.d.ts) - Create a type that strips `readonly` from the given type. Inverse of `Readonly<T>`.
|
|
107
118
|
- [`WritableDeep`](source/writable-deep.d.ts) - 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.
|
|
108
119
|
- [`Merge`](source/merge.d.ts) - Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
109
120
|
- [`ObjectMerge`](source/object-merge.d.ts) - Merge two object types into a new object type, where keys from the second override keys from the first.
|
|
110
121
|
- [`MergeDeep`](source/merge-deep.d.ts) - Merge two objects or two arrays/tuples recursively into a new type.
|
|
111
122
|
- [`MergeExclusive`](source/merge-exclusive.d.ts) - Create a type that has mutually exclusive keys.
|
|
112
|
-
- [`OverrideProperties`](source/override-properties.d.ts) - Override
|
|
113
|
-
- [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given keys.
|
|
114
|
-
- [`RequireExactlyOne`](source/require-exactly-one.d.ts) - Create a type that requires exactly
|
|
115
|
-
- [`RequireAllOrNone`](source/require-all-or-none.d.ts) - Create a type that requires all of the given keys or none of the given keys.
|
|
116
|
-
- [`RequireOneOrNone`](source/require-one-or-none.d.ts) - Create a type that requires exactly
|
|
123
|
+
- [`OverrideProperties`](source/override-properties.d.ts) - Override existing properties of the given type. Similar to `Merge`, but enforces that the original type has the properties you want to override.
|
|
124
|
+
- [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given keys, while keeping the remaining keys as is.
|
|
125
|
+
- [`RequireExactlyOne`](source/require-exactly-one.d.ts) - Create a type that requires exactly one of the given keys and disallows more, while keeping the remaining keys as is.
|
|
126
|
+
- [`RequireAllOrNone`](source/require-all-or-none.d.ts) - Create a type that requires all of the given keys or none of the given keys, while keeping the remaining keys as is.
|
|
127
|
+
- [`RequireOneOrNone`](source/require-one-or-none.d.ts) - Create a type that requires exactly one of the given keys or none of the given keys, while keeping the remaining keys as is.
|
|
117
128
|
- [`SingleKeyObject`](source/single-key-object.d.ts) - Create a type that only accepts an object with a single key.
|
|
118
|
-
- [`RequiredDeep`](source/required-deep.d.ts) - Create a deeply required version of another type.
|
|
119
|
-
- [`PickDeep`](source/pick-deep.d.ts) - Pick properties from a deeply-nested object.
|
|
120
|
-
- [`OmitDeep`](source/omit-deep.d.ts) - Omit properties from a deeply-nested object.
|
|
129
|
+
- [`RequiredDeep`](source/required-deep.d.ts) - Create a deeply required version of another type.
|
|
130
|
+
- [`PickDeep`](source/pick-deep.d.ts) - Pick properties from a deeply-nested object.
|
|
131
|
+
- [`OmitDeep`](source/omit-deep.d.ts) - Omit properties from a deeply-nested object.
|
|
121
132
|
- [`OmitIndexSignature`](source/omit-index-signature.d.ts) - Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
122
133
|
- [`PickIndexSignature`](source/pick-index-signature.d.ts) - Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
123
|
-
- [`PartialDeep`](source/partial-deep.d.ts) - Create a deeply optional version of another type.
|
|
134
|
+
- [`PartialDeep`](source/partial-deep.d.ts) - Create a deeply optional version of another type.
|
|
124
135
|
- [`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.
|
|
125
136
|
- [`UndefinedOnPartialDeep`](source/undefined-on-partial-deep.d.ts) - Create a deep version of another type where all optional keys are set to also accept `undefined`.
|
|
126
137
|
- [`UnwrapPartial`](source/unwrap-partial.d.ts) - Revert the `Partial` modifier on an object type.
|
|
127
|
-
- [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of
|
|
128
|
-
- [`LiteralUnion`](source/literal-union.d.ts) - Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
129
|
-
- [`Tagged`](source/tagged.d.ts) - Create a [tagged type](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d) that can support [multiple tags](https://github.com/sindresorhus/type-fest/issues/665) and [per-tag metadata](https://medium.com/@ethanresnick/advanced-typescript-tagged-types-improved-with-type-level-metadata-5072fc125fcf).
|
|
130
|
-
- [`UnwrapTagged`](source/tagged.d.ts) - Get the untagged portion of a tagged type created with `Tagged`.
|
|
138
|
+
- [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of another type.
|
|
139
|
+
- [`LiteralUnion`](source/literal-union.d.ts) - Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
140
|
+
- [`Tagged`](source/tagged.d.ts) - Create a [tagged type](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d) that can support [multiple tags](https://github.com/sindresorhus/type-fest/issues/665) and [per-tag metadata](https://medium.com/@ethanresnick/advanced-typescript-tagged-types-improved-with-type-level-metadata-5072fc125fcf).
|
|
141
|
+
- [`UnwrapTagged`](source/tagged.d.ts) - Get the untagged portion of a tagged type created with `Tagged`.
|
|
131
142
|
- [`InvariantOf`](source/invariant-of.d.ts) - Create an [invariant type](https://basarat.gitbook.io/typescript/type-system/type-compatibility#footnote-invariance), which is a type that does not accept supertypes and subtypes.
|
|
132
|
-
- [`SetOptional`](source/set-optional.d.ts) - Create a type that makes the given keys optional.
|
|
133
|
-
- [`SetReadonly`](source/set-readonly.d.ts) - Create a type that makes the given keys readonly.
|
|
134
|
-
- [`SetRequired`](source/set-required.d.ts) - Create a type that makes the given keys required.
|
|
135
|
-
- [`SetRequiredDeep`](source/set-required-deep.d.ts) -
|
|
136
|
-
- [`SetNonNullable`](source/set-non-nullable.d.ts) - Create a type that makes the given keys non-nullable.
|
|
143
|
+
- [`SetOptional`](source/set-optional.d.ts) - Create a type that makes the given keys optional, while keeping the remaining keys as is.
|
|
144
|
+
- [`SetReadonly`](source/set-readonly.d.ts) - Create a type that makes the given keys readonly, while keeping the remaining keys as is.
|
|
145
|
+
- [`SetRequired`](source/set-required.d.ts) - Create a type that makes the given keys required, while keeping the remaining keys as is.
|
|
146
|
+
- [`SetRequiredDeep`](source/set-required-deep.d.ts) - Create a type that makes the given keys required, with support for deeply nested key paths, while keeping the remaining keys as is.
|
|
147
|
+
- [`SetNonNullable`](source/set-non-nullable.d.ts) - Create a type that makes the given keys non-nullable, while keeping the remaining keys as is.
|
|
137
148
|
- [`SetNonNullableDeep`](source/set-non-nullable-deep.d.ts) - Create a type that makes the specified keys non-nullable (removes `null` and `undefined`), supports deeply nested key paths, and leaves all other keys unchanged.
|
|
149
|
+
- [`NonNullableDeep`](source/non-nullable-deep.d.ts) - Recursively removes `null` and `undefined` from the specified type.
|
|
138
150
|
- [`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.
|
|
139
|
-
- [`ConditionalKeys`](source/conditional-keys.d.ts) - Extract keys from a
|
|
140
|
-
- [`ConditionalPick`](source/conditional-pick.d.ts) -
|
|
141
|
-
- [`ConditionalPickDeep`](source/conditional-pick-deep.d.ts) -
|
|
142
|
-
- [`ConditionalExcept`](source/conditional-except.d.ts) -
|
|
151
|
+
- [`ConditionalKeys`](source/conditional-keys.d.ts) - Extract the keys from a type where the value type of the key extends the given `Condition`.
|
|
152
|
+
- [`ConditionalPick`](source/conditional-pick.d.ts) - Pick keys from the shape that matches the given `Condition`.
|
|
153
|
+
- [`ConditionalPickDeep`](source/conditional-pick-deep.d.ts) - Pick keys recursively from the shape that matches the given condition.
|
|
154
|
+
- [`ConditionalExcept`](source/conditional-except.d.ts) - Exclude keys from a shape that matches the given `Condition`.
|
|
143
155
|
- [`UnionToIntersection`](source/union-to-intersection.d.ts) - Convert a union type to an intersection type.
|
|
144
|
-
- [`LiteralToPrimitive`](source/literal-to-primitive.d.ts) -
|
|
156
|
+
- [`LiteralToPrimitive`](source/literal-to-primitive.d.ts) - Given a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) return the [primitive type](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) it belongs to, or `never` if it's not a primitive.
|
|
145
157
|
- [`LiteralToPrimitiveDeep`](source/literal-to-primitive-deep.d.ts) - Like `LiteralToPrimitive` except it converts literal types inside an object or array deeply.
|
|
146
158
|
- [`Stringified`](source/stringified.d.ts) - Create a type with the keys of the given type changed to `string` type.
|
|
147
159
|
- [`IterableElement`](source/iterable-element.d.ts) - Get the element type of an `Iterable`/`AsyncIterable`. For example, `Array`, `Set`, `Map`, generator, stream, etc.
|
|
148
|
-
- [`Entry`](source/entry.d.ts) - Create a type that
|
|
149
|
-
- [`Entries`](source/entries.d.ts) - Create a type that
|
|
160
|
+
- [`Entry`](source/entry.d.ts) - Create a type that describes a single key-value pair produced when calling a collection’s `entries` method.
|
|
161
|
+
- [`Entries`](source/entries.d.ts) - Create a type that describes the key-value pairs produced when calling a collection’s `entries` method.
|
|
150
162
|
- [`SetReturnType`](source/set-return-type.d.ts) - Create a function type with a return type of your choice and the same parameters as the given function type.
|
|
151
163
|
- [`SetParameterType`](source/set-parameter-type.d.ts) - Create a function that replaces some parameters with the given parameters.
|
|
152
164
|
- [`Simplify`](source/simplify.d.ts) - Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
@@ -154,21 +166,21 @@ Click the type names for complete docs.
|
|
|
154
166
|
- [`Get`](source/get.d.ts) - Get a deeply-nested property from an object using a key path, like [Lodash's `.get()`](https://lodash.com/docs/latest#get) function.
|
|
155
167
|
- [`KeyAsString`](source/key-as-string.d.ts) - Get keys of the given type as strings.
|
|
156
168
|
- [`Schema`](source/schema.d.ts) - Create a deep version of another object type where property values are recursively replaced into a given value type.
|
|
157
|
-
- [`Exact`](source/exact.d.ts) - Create a type that does not allow extra properties.
|
|
169
|
+
- [`Exact`](source/exact.d.ts) - Create a type that does not allow extra properties, meaning it only allows properties that are explicitly declared.
|
|
158
170
|
- [`KeysOfUnion`](source/keys-of-union.d.ts) - Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
159
171
|
- [`OptionalKeysOf`](source/optional-keys-of.d.ts) - Extract all optional keys from the given type.
|
|
160
|
-
- [`HasOptionalKeys`](source/has-optional-keys.d.ts) -
|
|
172
|
+
- [`HasOptionalKeys`](source/has-optional-keys.d.ts) - Returns a boolean for whether the given type has any optional fields.
|
|
161
173
|
- [`RequiredKeysOf`](source/required-keys-of.d.ts) - Extract all required keys from the given type.
|
|
162
|
-
- [`HasRequiredKeys`](source/has-required-keys.d.ts) -
|
|
174
|
+
- [`HasRequiredKeys`](source/has-required-keys.d.ts) - Returns a boolean for whether the given type has any required fields.
|
|
163
175
|
- [`ReadonlyKeysOf`](source/readonly-keys-of.d.ts) - Extract all readonly keys from the given type.
|
|
164
|
-
- [`HasReadonlyKeys`](source/has-readonly-keys.d.ts) -
|
|
165
|
-
- [`WritableKeysOf`](source/writable-keys-of.d.ts) - Extract all writable
|
|
166
|
-
- [`HasWritableKeys`](source/has-writable-keys.d.ts) -
|
|
176
|
+
- [`HasReadonlyKeys`](source/has-readonly-keys.d.ts) - Returns a boolean for whether the given type has any readonly fields.
|
|
177
|
+
- [`WritableKeysOf`](source/writable-keys-of.d.ts) - Extract all writable keys from the given type.
|
|
178
|
+
- [`HasWritableKeys`](source/has-writable-keys.d.ts) - Returns a boolean for whether the given type has any writable fields.
|
|
167
179
|
- [`Spread`](source/spread.d.ts) - Mimic the type inferred by TypeScript when merging two objects or two arrays/tuples using the spread syntax.
|
|
168
180
|
- [`IsEqual`](source/is-equal.d.ts) - Returns a boolean for whether the two given types are equal.
|
|
169
181
|
- [`TaggedUnion`](source/tagged-union.d.ts) - Create a union of types that share a common discriminant property.
|
|
170
|
-
- [`IntRange`](source/int-range.d.ts) - Generate a union of numbers
|
|
171
|
-
- [`IntClosedRange`](source/int-closed-range.d.ts) - Generate a union of numbers
|
|
182
|
+
- [`IntRange`](source/int-range.d.ts) - Generate a union of numbers between a specified start (inclusive) and end (exclusive), with an optional step.
|
|
183
|
+
- [`IntClosedRange`](source/int-closed-range.d.ts) - Generate a union of numbers between a specified start and end (both inclusive), with an optional step.
|
|
172
184
|
- [`ArrayIndices`](source/array-indices.d.ts) - Provides valid indices for a constant array or tuple.
|
|
173
185
|
- [`ArrayValues`](source/array-values.d.ts) - Provides all values for a constant array or tuple.
|
|
174
186
|
- [`ArraySplice`](source/array-splice.d.ts) - Create a new array type by adding or removing elements at a specified index range in the original array.
|
|
@@ -179,11 +191,14 @@ Click the type names for complete docs.
|
|
|
179
191
|
- [`SharedUnionFieldsDeep`](source/shared-union-fields-deep.d.ts) - Create a type with shared fields from a union of object types, deeply traversing nested structures.
|
|
180
192
|
- [`AllUnionFields`](source/all-union-fields.d.ts) - Create a type with all fields from a union of object types.
|
|
181
193
|
- [`DistributedOmit`](source/distributed-omit.d.ts) - Omits keys from a type, distributing the operation over a union.
|
|
182
|
-
- [`DistributedPick`](source/distributed-pick.d.ts) -
|
|
183
|
-
- [`And`](source/and.d.ts) - Returns a boolean for whether two given types are both true
|
|
184
|
-
- [`Or`](source/or.d.ts) - Returns a boolean for whether either of two given types is true
|
|
185
|
-
- [`Xor`](source/xor.d.ts) - Returns a boolean for whether only one of two given types is true
|
|
194
|
+
- [`DistributedPick`](source/distributed-pick.d.ts) - Pick keys from a type, distributing the operation over a union.
|
|
195
|
+
- [`And`](source/and.d.ts) - Returns a boolean for whether two given types are both `true`.
|
|
196
|
+
- [`Or`](source/or.d.ts) - Returns a boolean for whether either of two given types is `true`.
|
|
197
|
+
- [`Xor`](source/xor.d.ts) - Returns a boolean for whether only one of two given types is `true`.
|
|
198
|
+
- [`AndAll`](source/and-all.d.ts) - Returns a boolean for whether all of the given elements are `true`.
|
|
199
|
+
- [`OrAll`](source/or-all.d.ts) - Returns a boolean for whether any of the given elements is `true`.
|
|
186
200
|
- [`AllExtend`](source/all-extend.d.ts) - Returns a boolean for whether every element in an array type extends another type.
|
|
201
|
+
- [`SomeExtend`](source/some-extend.d.ts) - Returns a boolean for whether some element in an array type extends another type.
|
|
187
202
|
- [`NonEmptyTuple`](source/non-empty-tuple.d.ts) - Matches any non-empty tuple.
|
|
188
203
|
- [`NonEmptyString`](source/non-empty-string.d.ts) - Matches any non-empty string.
|
|
189
204
|
- [`FindGlobalType`](source/find-global-type.d.ts) - Tries to find the type of a global with the given name.
|
|
@@ -191,6 +206,9 @@ Click the type names for complete docs.
|
|
|
191
206
|
- [`ConditionalSimplify`](source/conditional-simplify.d.ts) - Simplifies a type while including and/or excluding certain types from being simplified.
|
|
192
207
|
- [`ConditionalSimplifyDeep`](source/conditional-simplify-deep.d.ts) - Recursively simplifies a type while including and/or excluding certain types from being simplified.
|
|
193
208
|
- [`ExclusifyUnion`](source/exclusify-union.d.ts) - Ensure mutual exclusivity in object unions by adding other members’ keys as `?: never`.
|
|
209
|
+
- [`Optional`](source/optional.d.ts) - Create a type that represents either the value or `undefined`, while stripping `null` from the type.
|
|
210
|
+
- [`UnionMember`](source/union-member.d.ts) - Returns an arbitrary member of a union type.
|
|
211
|
+
- [`UnionLength`](source/union-length.d.ts) - Returns the length of a union type.
|
|
194
212
|
|
|
195
213
|
### Type Guard
|
|
196
214
|
|
|
@@ -221,7 +239,7 @@ Click the type names for complete docs.
|
|
|
221
239
|
|
|
222
240
|
- [`Jsonify`](source/jsonify.d.ts) - Transform a type to one that is assignable to the `JsonValue` type.
|
|
223
241
|
- [`Jsonifiable`](source/jsonifiable.d.ts) - Matches a value that can be losslessly converted to JSON.
|
|
224
|
-
- [`JsonPrimitive`](source/json-value.d.ts) - Matches
|
|
242
|
+
- [`JsonPrimitive`](source/json-value.d.ts) - Matches any valid JSON primitive value.
|
|
225
243
|
- [`JsonObject`](source/json-value.d.ts) - Matches a JSON object.
|
|
226
244
|
- [`JsonArray`](source/json-value.d.ts) - Matches a JSON array.
|
|
227
245
|
- [`JsonValue`](source/json-value.d.ts) - Matches any valid JSON value.
|
|
@@ -234,13 +252,13 @@ Click the type names for complete docs.
|
|
|
234
252
|
|
|
235
253
|
- [`Promisable`](source/promisable.d.ts) - Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
|
236
254
|
- [`AsyncReturnType`](source/async-return-type.d.ts) - Unwrap the return type of a function that returns a `Promise`.
|
|
237
|
-
- [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type.
|
|
255
|
+
- [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type, by boxing the return type in `Promise` while keeping the same parameter types.
|
|
238
256
|
|
|
239
257
|
### String
|
|
240
258
|
|
|
241
259
|
- [`Trim`](source/trim.d.ts) - Remove leading and trailing spaces from a string.
|
|
242
260
|
- [`Split`](source/split.d.ts) - Represents an array of strings split using a given character or character set.
|
|
243
|
-
- [`Words`](source/words.d.ts) -
|
|
261
|
+
- [`Words`](source/words.d.ts) - Split a string similar to Lodash's `_.words()` function.
|
|
244
262
|
- [`Replace`](source/replace.d.ts) - Represents a string with some or all matches replaced by a replacement.
|
|
245
263
|
- [`StringSlice`](source/string-slice.d.ts) - Returns a string slice of a given range, just like `String#slice()`.
|
|
246
264
|
- [`StringRepeat`](source/string-repeat.d.ts) - Returns a new string which contains the specified number of copies of a given string, just like `String#repeat()`.
|
|
@@ -255,8 +273,8 @@ Click the type names for complete docs.
|
|
|
255
273
|
- [`ArrayElement`](source/array-element.d.ts) - Extracts the element type of an array or tuple.
|
|
256
274
|
- [`LastArrayElement`](source/last-array-element.d.ts) - Extract the type of the last element of an array.
|
|
257
275
|
- [`FixedLengthArray`](source/fixed-length-array.d.ts) - Create a type that represents an array of the given type and length. The `Array` prototype methods that manipulate its length are excluded from the resulting type.
|
|
258
|
-
- [`MultidimensionalArray`](source/multidimensional-array.d.ts) - Create a type that represents a multidimensional array of the given type and
|
|
259
|
-
- [`MultidimensionalReadonlyArray`](source/multidimensional-readonly-array.d.ts) - Create a type that represents a multidimensional readonly array of the given type and
|
|
276
|
+
- [`MultidimensionalArray`](source/multidimensional-array.d.ts) - Create a type that represents a multidimensional array of the given type and dimension.
|
|
277
|
+
- [`MultidimensionalReadonlyArray`](source/multidimensional-readonly-array.d.ts) - Create a type that represents a multidimensional readonly array of the given type and dimension.
|
|
260
278
|
- [`ReadonlyTuple`](source/readonly-tuple.d.ts) - Create a type that represents a read-only tuple of the given type and length.
|
|
261
279
|
- [`TupleToUnion`](source/tuple-to-union.d.ts) - Convert a tuple/array into a union type of its elements.
|
|
262
280
|
- [`UnionToTuple`](source/union-to-tuple.d.ts) - Convert a union type into an unordered tuple type of its elements.
|
|
@@ -266,6 +284,7 @@ Click the type names for complete docs.
|
|
|
266
284
|
- [`ExtractRestElement`](source/extract-rest-element.d.ts) - Extract the [`rest`](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) element type from an array.
|
|
267
285
|
- [`ExcludeRestElement`](source/exclude-rest-element.d.ts) - Create a tuple with the [`rest`](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) element removed.
|
|
268
286
|
- [`ArrayReverse`](source/array-reverse.d.ts) - Reverse the order of elements in a tuple type.
|
|
287
|
+
- [`ArrayLength`](source/array-length.d.ts) - Return the length of an array. Equivalent to `T['length']` where `T` extends any array.
|
|
269
288
|
|
|
270
289
|
### Numeric
|
|
271
290
|
|
|
@@ -281,29 +300,30 @@ Click the type names for complete docs.
|
|
|
281
300
|
- [`NonNegativeInteger`](source/numeric.d.ts) - A non-negative (`0 <= x < ∞`) `number` that is an integer.
|
|
282
301
|
- [`IsNegative`](source/numeric.d.ts) - Returns a boolean for whether the given number is a negative number.
|
|
283
302
|
- [`IsFloat`](source/is-float.d.ts) - Returns a boolean for whether the given number is a float, like `1.5` or `-1.5`.
|
|
284
|
-
- [`IsInteger`](source/is-integer.d.ts) - Returns a boolean for whether the given number is
|
|
303
|
+
- [`IsInteger`](source/is-integer.d.ts) - Returns a boolean for whether the given number is an integer, like `-5`, `1.0`, or `100`.
|
|
285
304
|
- [`GreaterThan`](source/greater-than.d.ts) - Returns a boolean for whether a given number is greater than another number.
|
|
286
305
|
- [`GreaterThanOrEqual`](source/greater-than-or-equal.d.ts) - Returns a boolean for whether a given number is greater than or equal to another number.
|
|
287
306
|
- [`LessThan`](source/less-than.d.ts) - Returns a boolean for whether a given number is less than another number.
|
|
288
307
|
- [`LessThanOrEqual`](source/less-than-or-equal.d.ts) - Returns a boolean for whether a given number is less than or equal to another number.
|
|
289
308
|
- [`Sum`](source/sum.d.ts) - Returns the sum of two numbers.
|
|
290
309
|
- [`Subtract`](source/subtract.d.ts) - Returns the difference between two numbers.
|
|
310
|
+
- [`Absolute`](source/absolute.d.ts) - Returns the absolute value of the specified number or bigint.
|
|
291
311
|
|
|
292
312
|
### Change case
|
|
293
313
|
|
|
294
|
-
- [`CamelCase`](source/camel-case.d.ts) - Convert a string literal to camel-case
|
|
295
|
-
- [`CamelCasedProperties`](source/camel-cased-properties.d.ts) - Convert object properties to camel
|
|
296
|
-
- [`CamelCasedPropertiesDeep`](source/camel-cased-properties-deep.d.ts) - Convert object properties to camel
|
|
297
|
-
- [`KebabCase`](source/kebab-case.d.ts) - Convert a string literal to kebab-case
|
|
298
|
-
- [`KebabCasedProperties`](source/kebab-cased-properties.d.ts) - Convert object properties to kebab
|
|
299
|
-
- [`KebabCasedPropertiesDeep`](source/kebab-cased-properties-deep.d.ts) - Convert object properties to kebab
|
|
300
|
-
- [`PascalCase`](source/pascal-case.d.ts) - Convert a string literal to pascal-case
|
|
301
|
-
- [`PascalCasedProperties`](source/pascal-cased-properties.d.ts) - Convert object properties to pascal
|
|
302
|
-
- [`PascalCasedPropertiesDeep`](source/pascal-cased-properties-deep.d.ts) - Convert object properties to pascal
|
|
303
|
-
- [`SnakeCase`](source/snake-case.d.ts) - Convert a string literal to snake-case
|
|
304
|
-
- [`SnakeCasedProperties`](source/snake-cased-properties.d.ts) - Convert object properties to snake
|
|
305
|
-
- [`SnakeCasedPropertiesDeep`](source/snake-cased-properties-deep.d.ts) - Convert object properties to snake
|
|
306
|
-
- [`ScreamingSnakeCase`](source/screaming-snake-case.d.ts) - Convert a string literal to screaming-snake-case
|
|
314
|
+
- [`CamelCase`](source/camel-case.d.ts) - Convert a string literal to camel-case.
|
|
315
|
+
- [`CamelCasedProperties`](source/camel-cased-properties.d.ts) - Convert top-level object properties to camel case.
|
|
316
|
+
- [`CamelCasedPropertiesDeep`](source/camel-cased-properties-deep.d.ts) - Convert object properties to camel case recursively.
|
|
317
|
+
- [`KebabCase`](source/kebab-case.d.ts) - Convert a string literal to kebab-case.
|
|
318
|
+
- [`KebabCasedProperties`](source/kebab-cased-properties.d.ts) - Convert top-level object properties to kebab case.
|
|
319
|
+
- [`KebabCasedPropertiesDeep`](source/kebab-cased-properties-deep.d.ts) - Convert object properties to kebab case recursively.
|
|
320
|
+
- [`PascalCase`](source/pascal-case.d.ts) - Convert a string literal to pascal-case.
|
|
321
|
+
- [`PascalCasedProperties`](source/pascal-cased-properties.d.ts) - Convert top-level object properties to pascal case.
|
|
322
|
+
- [`PascalCasedPropertiesDeep`](source/pascal-cased-properties-deep.d.ts) - Convert object properties to pascal case recursively.
|
|
323
|
+
- [`SnakeCase`](source/snake-case.d.ts) - Convert a string literal to snake-case.
|
|
324
|
+
- [`SnakeCasedProperties`](source/snake-cased-properties.d.ts) - Convert top-level object properties to snake case.
|
|
325
|
+
- [`SnakeCasedPropertiesDeep`](source/snake-cased-properties-deep.d.ts) - Convert object properties to snake case recursively.
|
|
326
|
+
- [`ScreamingSnakeCase`](source/screaming-snake-case.d.ts) - Convert a string literal to screaming-snake-case.
|
|
307
327
|
- [`DelimiterCase`](source/delimiter-case.d.ts) - Convert a string literal to a custom string delimiter casing.
|
|
308
328
|
- [`DelimiterCasedProperties`](source/delimiter-cased-properties.d.ts) - Convert object properties to a custom string delimiter casing.
|
|
309
329
|
- [`DelimiterCasedPropertiesDeep`](source/delimiter-cased-properties-deep.d.ts) - Convert object properties to a custom string delimiter casing recursively.
|
|
@@ -311,7 +331,7 @@ Click the type names for complete docs.
|
|
|
311
331
|
### Miscellaneous
|
|
312
332
|
|
|
313
333
|
- [`GlobalThis`](source/global-this.d.ts) - Declare locally scoped properties on `globalThis`.
|
|
314
|
-
- [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file).
|
|
334
|
+
- [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Also includes types for fields used by other popular projects, like TypeScript and Yarn.
|
|
315
335
|
- [`TsConfigJson`](source/tsconfig-json.d.ts) - Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
|
|
316
336
|
|
|
317
337
|
### Improved built-in
|
|
@@ -319,6 +339,7 @@ Click the type names for complete docs.
|
|
|
319
339
|
- [`ExtendsStrict`](source/extends-strict.d.ts) - A stricter, non-distributive version of `extends` for checking whether one type is assignable to another.
|
|
320
340
|
- [`ExtractStrict`](source/extract-strict.d.ts) - A stricter version of `Extract<T, U>` that ensures every member of `U` can successfully extract something from `T`.
|
|
321
341
|
- [`ExcludeStrict`](source/exclude-strict.d.ts) - A stricter version of `Exclude<T, U>` that ensures every member of `U` can successfully exclude something from `T`.
|
|
342
|
+
- [`ExcludeExactly`](source/exclude-exactly.d.ts) - A stricter version of `Exclude<T, U>` that excludes types only when they are exactly identical.
|
|
322
343
|
|
|
323
344
|
## Declined types
|
|
324
345
|
|
|
@@ -353,13 +374,17 @@ Click the type names for complete docs.
|
|
|
353
374
|
- `PickByTypes` - See [`ConditionalPick`](source/conditional-pick.d.ts)
|
|
354
375
|
- `HomomorphicOmit` - See [`Except`](source/except.d.ts)
|
|
355
376
|
- `IfAny`, `IfNever`, `If*` - See [`If`](source/if.d.ts)
|
|
377
|
+
- `Maybe`, `Option` - See [`Optional`](source/optional.d.ts)
|
|
356
378
|
- `MaybePromise` - See [`Promisable`](source/promisable.d.ts)
|
|
357
379
|
- `ReadonlyTuple` - See [`TupleOf`](source/tuple-of.d.ts)
|
|
380
|
+
- `LastOfUnion` - See [`UnionMember`](source/union-member.d.ts)
|
|
381
|
+
- `FirstOfUnion` - See [`UnionMember`](source/union-member.d.ts)
|
|
358
382
|
|
|
359
383
|
## Tips
|
|
360
384
|
|
|
361
385
|
### Extending existing types
|
|
362
386
|
|
|
387
|
+
<!-- eslint-disable-next-line type-fest/readme-jsdoc-sync -->
|
|
363
388
|
- [`PackageJson`](source/package-json.d.ts) - There are a lot of tools that place extra configurations inside the `package.json` file. You can extend `PackageJson` to support these additional configurations.
|
|
364
389
|
<details>
|
|
365
390
|
<summary>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type {StringToNumber} from './internal/string.d.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Returns the absolute value of the specified number or bigint.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {Absolute} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
type A = Absolute<-1>;
|
|
11
|
+
//=> 1
|
|
12
|
+
|
|
13
|
+
type B = Absolute<1>;
|
|
14
|
+
//=> 1
|
|
15
|
+
|
|
16
|
+
type C = Absolute<0>;
|
|
17
|
+
//=> 0
|
|
18
|
+
|
|
19
|
+
type D = Absolute<-1.025>;
|
|
20
|
+
//=> 1.025
|
|
21
|
+
|
|
22
|
+
type E = Absolute<-9999n>;
|
|
23
|
+
//=> 9999n
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Returns back the same type if the input is not a literal type.
|
|
27
|
+
|
|
28
|
+
@example
|
|
29
|
+
```
|
|
30
|
+
import type {Absolute} from 'type-fest';
|
|
31
|
+
|
|
32
|
+
type A = Absolute<number>;
|
|
33
|
+
//=> number
|
|
34
|
+
|
|
35
|
+
type B = Absolute<bigint>;
|
|
36
|
+
//=> bigint
|
|
37
|
+
|
|
38
|
+
type C = Absolute<number | bigint>;
|
|
39
|
+
//=> number | bigint
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
@category Numeric
|
|
43
|
+
*/
|
|
44
|
+
export type Absolute<N extends number | bigint> = N extends bigint // Also, distributes `N`
|
|
45
|
+
? `${N}` extends `-${infer Magnitude extends bigint}`
|
|
46
|
+
? Magnitude
|
|
47
|
+
: N
|
|
48
|
+
: `${N}` extends `-${infer Magnitude}` // This doesn't use the `extends number` constraint approach because that fails with the `-Infinity` case
|
|
49
|
+
? StringToNumber<Magnitude>
|
|
50
|
+
: N;
|
|
51
|
+
|
|
52
|
+
export {};
|
package/source/all-extend.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {If} from './if.d.ts';
|
|
2
1
|
import type {CollapseRestElement} from './internal/array.d.ts';
|
|
3
2
|
import type {ApplyDefaultOptions} from './internal/object.d.ts';
|
|
4
3
|
import type {IfNotAnyOrNever, Not} from './internal/type.d.ts';
|
|
@@ -104,17 +103,17 @@ type B = AllExtend<[1?, 2?, 3?], number | undefined>;
|
|
|
104
103
|
export type AllExtend<TArray extends UnknownArray, Type, Options extends AllExtendOptions = {}> =
|
|
105
104
|
_AllExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<AllExtendOptions, DefaultAllExtendOptions, Options>>;
|
|
106
105
|
|
|
107
|
-
type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllExtendOptions>> = IfNotAnyOrNever<TArray,
|
|
106
|
+
type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllExtendOptions>> = IfNotAnyOrNever<TArray,
|
|
108
107
|
TArray extends readonly [infer First, ...infer Rest]
|
|
109
108
|
? IsNever<First> extends true
|
|
110
|
-
? Or<IsNever<Type>, Not<Options['strictNever']>> extends true
|
|
111
|
-
// If target `Type` is also `never`
|
|
109
|
+
? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true
|
|
110
|
+
// If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, recurse further.
|
|
112
111
|
? _AllExtend<Rest, Type, Options>
|
|
113
112
|
: false
|
|
114
113
|
: First extends Type
|
|
115
114
|
? _AllExtend<Rest, Type, Options>
|
|
116
115
|
: false
|
|
117
|
-
: true
|
|
118
|
-
|
|
116
|
+
: true,
|
|
117
|
+
false, false>;
|
|
119
118
|
|
|
120
119
|
export {};
|
|
@@ -69,23 +69,23 @@ function displayPetInfoWithAllUnionFields(petInfo: AllUnionFields<Cat | Dog>) {
|
|
|
69
69
|
@category Union
|
|
70
70
|
*/
|
|
71
71
|
export type AllUnionFields<Union> =
|
|
72
|
-
Extract<Union, NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | UnknownArray> extends infer SkippedMembers
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
72
|
+
Extract<Union, NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | UnknownArray> extends infer SkippedMembers
|
|
73
|
+
? Exclude<Union, SkippedMembers> extends infer RelevantMembers
|
|
74
|
+
? // eslint-disable-line @stylistic/operator-linebreak
|
|
75
|
+
| SkippedMembers
|
|
76
|
+
| Simplify<
|
|
77
|
+
// Include fields that are common in all union members
|
|
78
|
+
SharedUnionFields<RelevantMembers>
|
|
79
|
+
// Include readonly fields present in any union member
|
|
80
|
+
& {
|
|
81
|
+
readonly [P in ReadonlyKeysOfUnion<RelevantMembers>]?: ValueOfUnion<RelevantMembers, P & KeysOfUnion<RelevantMembers>>
|
|
82
|
+
}
|
|
83
|
+
// Include remaining fields that are neither common nor readonly
|
|
84
|
+
& {
|
|
85
|
+
[P in Exclude<KeysOfUnion<RelevantMembers>, ReadonlyKeysOfUnion<RelevantMembers> | keyof RelevantMembers>]?: ValueOfUnion<RelevantMembers, P>
|
|
86
|
+
}
|
|
87
|
+
>
|
|
88
|
+
: never
|
|
89
|
+
: never;
|
|
90
90
|
|
|
91
91
|
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type {AllExtend} from './all-extend.d.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Returns a boolean for whether all of the given elements are `true`.
|
|
5
|
+
|
|
6
|
+
Use-cases:
|
|
7
|
+
- Check if all conditions in a list of booleans are met.
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import type {AndAll} from 'type-fest';
|
|
12
|
+
|
|
13
|
+
type TTT = AndAll<[true, true, true]>;
|
|
14
|
+
//=> true
|
|
15
|
+
|
|
16
|
+
type TTF = AndAll<[true, true, false]>;
|
|
17
|
+
//=> false
|
|
18
|
+
|
|
19
|
+
type TFT = AndAll<[true, false, true]>;
|
|
20
|
+
//=> false
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
|
|
24
|
+
For example, `AndAll<[true, boolean]>` expands to `AndAll<[true, true]> | AndAll<[true, false]>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
25
|
+
|
|
26
|
+
@example
|
|
27
|
+
```
|
|
28
|
+
import type {AndAll} from 'type-fest';
|
|
29
|
+
|
|
30
|
+
type A = AndAll<[true, boolean]>;
|
|
31
|
+
//=> boolean
|
|
32
|
+
|
|
33
|
+
type B = AndAll<[false, boolean]>;
|
|
34
|
+
//=> false
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Note: If any of the elements is `never`, the result becomes `false`.
|
|
38
|
+
|
|
39
|
+
@example
|
|
40
|
+
```
|
|
41
|
+
import type {AndAll} from 'type-fest';
|
|
42
|
+
|
|
43
|
+
type A = AndAll<[true, true, never]>;
|
|
44
|
+
//=> false
|
|
45
|
+
|
|
46
|
+
type B = AndAll<[false, never, never]>;
|
|
47
|
+
//=> false
|
|
48
|
+
|
|
49
|
+
type C = AndAll<[never, never, never]>;
|
|
50
|
+
//=> false
|
|
51
|
+
|
|
52
|
+
type D = AndAll<[boolean, true, never]>;
|
|
53
|
+
//=> false
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
|
|
57
|
+
|
|
58
|
+
@example
|
|
59
|
+
```
|
|
60
|
+
import type {AndAll} from 'type-fest';
|
|
61
|
+
|
|
62
|
+
type A = AndAll<[false, any]>;
|
|
63
|
+
//=> false
|
|
64
|
+
|
|
65
|
+
type B = AndAll<[true, any]>;
|
|
66
|
+
//=> boolean
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Note: `AndAll<[]>` evaluates to `true` due to the concept of [vacuous truth](https://en.wikipedia.org/wiki/Logical_conjunction#:~:text=In%20keeping%20with%20the%20concept%20of%20vacuous%20truth%2C%20when%20conjunction%20is%20defined%20as%20an%20operator%20or%20function%20of%20arbitrary%20arity%2C%20the%20empty%20conjunction%20(AND%2Ding%20over%20an%20empty%20set%20of%20operands)%20is%20often%20defined%20as%20having%20the%20result%20true.), i.e., there are no `false` elements in an empty tuple.
|
|
70
|
+
|
|
71
|
+
@see {@link And}
|
|
72
|
+
@see {@link OrAll}
|
|
73
|
+
*/
|
|
74
|
+
export type AndAll<T extends readonly boolean[]> = AllExtend<T, true>;
|
|
75
|
+
|
|
76
|
+
export {};
|
package/source/and.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {AndAll} from './and-all.d.ts';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
Returns a boolean for whether two given types are both true
|
|
4
|
+
Returns a boolean for whether two given types are both `true`.
|
|
5
5
|
|
|
6
6
|
Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
|
|
7
7
|
|
|
@@ -73,9 +73,10 @@ type G = And<never, never>;
|
|
|
73
73
|
//=> false
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
@see {@link AndAll}
|
|
76
77
|
@see {@link Or}
|
|
77
78
|
@see {@link Xor}
|
|
78
79
|
*/
|
|
79
|
-
export type And<A extends boolean, B extends boolean> =
|
|
80
|
+
export type And<A extends boolean, B extends boolean> = AndAll<[A, B]>;
|
|
80
81
|
|
|
81
82
|
export {};
|