@depup/type-fest 5.5.0-depup.0 → 5.10.0-depup.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/README.md +2 -2
- package/changes.json +1 -1
- package/index.d.ts +17 -8
- package/package.json +9 -6
- package/readme.md +75 -61
- package/source/absolute.d.ts +52 -0
- package/source/all-extend.d.ts +9 -5
- package/source/all-union-fields.d.ts +18 -18
- package/source/and.d.ts +1 -1
- package/source/array-reverse.d.ts +17 -15
- package/source/array-splice.d.ts +24 -24
- package/source/array-tail.d.ts +7 -7
- 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-keys.d.ts +1 -1
- package/source/delimiter-case.d.ts +11 -9
- 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 +11 -11
- package/source/exclude-rest-element.d.ts +4 -4
- package/source/exclusify-union.d.ts +4 -4
- package/source/extends-strict.d.ts +129 -22
- package/source/extract-exactly.d.ts +56 -0
- package/source/get.d.ts +1 -1
- package/source/greater-than.d.ts +3 -2
- 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 +5 -4
- package/source/int-range.d.ts +57 -12
- package/source/internal/array.d.ts +22 -21
- package/source/internal/keys.d.ts +9 -9
- package/source/internal/numeric.d.ts +19 -65
- package/source/internal/object.d.ts +44 -6
- package/source/internal/string.d.ts +1 -76
- package/source/internal/tuple.d.ts +2 -2
- package/source/internal/type.d.ts +16 -10
- package/source/is-boolean-literal.d.ts +39 -0
- package/source/is-integer.d.ts +8 -8
- package/source/is-literal.d.ts +43 -267
- package/source/is-numeric-literal.d.ts +50 -0
- package/source/is-string-literal.d.ts +72 -0
- package/source/is-symbol-literal.d.ts +39 -0
- package/source/is-tuple.d.ts +3 -3
- package/source/is-union.d.ts +12 -12
- package/source/iterable-element.d.ts +5 -5
- package/source/jsonify.d.ts +5 -9
- 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/last-array-element.d.ts +66 -13
- package/source/less-than-or-equal.d.ts +1 -1
- package/source/literal-to-primitive.d.ts +1 -1
- package/source/literal-union.d.ts +1 -1
- package/source/merge-deep.d.ts +3 -3
- package/source/merge-exclusive.d.ts +3 -3
- 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/object-merge.d.ts +21 -16
- package/source/omit-deep.d.ts +22 -22
- package/source/or.d.ts +1 -1
- 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 +2 -0
- package/source/readonly-deep.d.ts +5 -3
- package/source/remove-prefix.d.ts +16 -34
- package/source/remove-suffix.d.ts +114 -0
- package/source/rename-keys.d.ts +163 -0
- package/source/replace.d.ts +2 -2
- package/source/require-all-or-none.d.ts +5 -5
- package/source/require-at-least-one.d.ts +9 -11
- package/source/require-exactly-one.d.ts +7 -7
- package/source/require-one-or-none.d.ts +5 -5
- package/source/required-deep.d.ts +3 -1
- package/source/schema.d.ts +16 -8
- package/source/screaming-snake-case.d.ts +1 -0
- package/source/set-non-nullable-deep.d.ts +8 -4
- package/source/set-non-nullable.d.ts +1 -1
- package/source/set-optional.d.ts +5 -5
- package/source/set-readonly.d.ts +3 -3
- package/source/set-required-deep.d.ts +3 -2
- package/source/set-required.d.ts +13 -12
- package/source/shared-union-fields-deep.d.ts +6 -4
- 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 +9 -5
- package/source/split-on-rest-element.d.ts +20 -17
- package/source/split.d.ts +22 -11
- package/source/string-length.d.ts +38 -0
- package/source/string-repeat.d.ts +48 -21
- package/source/string-slice.d.ts +1 -1
- package/source/string-to-array.d.ts +97 -0
- package/source/string-to-number.d.ts +67 -0
- package/source/subtract.d.ts +4 -3
- package/source/sum.d.ts +5 -4
- package/source/tagged.d.ts +3 -5
- package/source/tsconfig-json.d.ts +40 -8
- package/source/tuple-of.d.ts +42 -8
- package/source/typed-array.d.ts +6 -0
- package/source/union-length.d.ts +27 -0
- package/source/union-max.d.ts +56 -0
- package/source/union-to-intersection.d.ts +1 -1
- package/source/union-to-tuple.d.ts +8 -4
- package/source/unwrap-required.d.ts +37 -0
- package/source/words.d.ts +30 -4
- package/source/writable.d.ts +14 -14
- package/source/xor.d.ts +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type {ApplyDefaultOptions} from './internal/object.d.ts';
|
|
2
|
+
import type {IfNotAnyOrNever} from './internal/type.d.ts';
|
|
3
|
+
import type {IsStringLiteral} from './is-string-literal.d.ts';
|
|
4
|
+
import type {Or} from './or.d.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
@see {@link StringToArray}
|
|
8
|
+
*/
|
|
9
|
+
export type StringToArrayOptions = {
|
|
10
|
+
/**
|
|
11
|
+
When enabled, non-literal parts of the string (e.g., `string`, `Uppercase<string>`) are mapped as single elements instead of being mapped as a rest element.
|
|
12
|
+
|
|
13
|
+
Note: Enabling this option can produce misleading results that might not reflect the actual runtime behavior.
|
|
14
|
+
For example, `StringToArray<string, {mapNonLiteralsDirectly: true}>` returns `[string]`, but at runtime, the string could be `'abc'` (which satisfies `string`), and converting it to an array would result in `['a', 'b', 'c']`, which doesn't satisfy `[string]`.
|
|
15
|
+
|
|
16
|
+
So, it is recommended to not enable this option unless you are aware of the implications.
|
|
17
|
+
|
|
18
|
+
@default false
|
|
19
|
+
|
|
20
|
+
@example
|
|
21
|
+
```
|
|
22
|
+
import type {StringToArray} from 'type-fest';
|
|
23
|
+
|
|
24
|
+
type A = StringToArray<string, {mapNonLiteralsDirectly: false}>;
|
|
25
|
+
//=> string[]
|
|
26
|
+
|
|
27
|
+
type B = StringToArray<string, {mapNonLiteralsDirectly: true}>;
|
|
28
|
+
//=> [string]
|
|
29
|
+
|
|
30
|
+
type C = StringToArray<`on${string}`, {mapNonLiteralsDirectly: false}>;
|
|
31
|
+
//=> ['o', 'n', ...string[]]
|
|
32
|
+
|
|
33
|
+
type D = StringToArray<`on${string}`, {mapNonLiteralsDirectly: true}>;
|
|
34
|
+
//=> ['o', 'n', string]
|
|
35
|
+
|
|
36
|
+
type E = StringToArray<`${string}xyz`, {mapNonLiteralsDirectly: false}>;
|
|
37
|
+
//=> [...string[], 'x', 'y', 'z']
|
|
38
|
+
|
|
39
|
+
type F = StringToArray<`${string}xyz`, {mapNonLiteralsDirectly: true}>;
|
|
40
|
+
//=> [string, 'x', 'y', 'z']
|
|
41
|
+
```
|
|
42
|
+
*/
|
|
43
|
+
mapNonLiteralsDirectly?: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type DefaultStringToArrayOptions = {
|
|
47
|
+
mapNonLiteralsDirectly: false;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
Returns an array of the characters of the specified string.
|
|
52
|
+
|
|
53
|
+
@example
|
|
54
|
+
```
|
|
55
|
+
import type {StringToArray} from 'type-fest';
|
|
56
|
+
|
|
57
|
+
type A = StringToArray<'abcde'>;
|
|
58
|
+
//=> ['a', 'b', 'c', 'd', 'e']
|
|
59
|
+
|
|
60
|
+
type B = StringToArray<''>;
|
|
61
|
+
//=> []
|
|
62
|
+
|
|
63
|
+
type C = StringToArray<string>;
|
|
64
|
+
//=> string[]
|
|
65
|
+
|
|
66
|
+
type D = StringToArray<`foo${string}bar`>;
|
|
67
|
+
//=> ['f', 'o', 'o', ...string[], 'b', 'a', 'r']
|
|
68
|
+
|
|
69
|
+
type E = StringToArray<`foo${string}bar`, {mapNonLiteralsDirectly: true}>;
|
|
70
|
+
//=> ['f', 'o', 'o', string, 'b', 'a', 'r']
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
@see {@link StringToArrayOptions}
|
|
74
|
+
|
|
75
|
+
@category String
|
|
76
|
+
*/
|
|
77
|
+
export type StringToArray<S extends string, Options extends StringToArrayOptions = {}> =
|
|
78
|
+
IfNotAnyOrNever<
|
|
79
|
+
S,
|
|
80
|
+
{
|
|
81
|
+
ifNot: _StringToArray<S, ApplyDefaultOptions<StringToArrayOptions, DefaultStringToArrayOptions, Options>>;
|
|
82
|
+
ifAny: unknown[];
|
|
83
|
+
}
|
|
84
|
+
>;
|
|
85
|
+
|
|
86
|
+
type _StringToArray<S extends string, Options extends Required<StringToArrayOptions>, Accumulator extends string[] = []> =
|
|
87
|
+
S extends `${infer First}${infer Rest}`
|
|
88
|
+
? Or<IsStringLiteral<First>, Options['mapNonLiteralsDirectly']> extends true
|
|
89
|
+
? _StringToArray<Rest, Options, [...Accumulator, First]>
|
|
90
|
+
: _StringToArray<Rest, Options, [...Accumulator, ...First[]]>
|
|
91
|
+
: S extends ''
|
|
92
|
+
? Accumulator
|
|
93
|
+
: Options['mapNonLiteralsDirectly'] extends true
|
|
94
|
+
? [...Accumulator, S]
|
|
95
|
+
: [...Accumulator, ...S[]];
|
|
96
|
+
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type {IfNotAnyOrNever} from './internal/type.d.ts';
|
|
2
|
+
import type {NegativeInfinity, PositiveInfinity} from './numeric.d.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Converts a numeric string to a number.
|
|
6
|
+
|
|
7
|
+
@example
|
|
8
|
+
```
|
|
9
|
+
import type {StringToNumber} from 'type-fest';
|
|
10
|
+
|
|
11
|
+
type PositiveInteger = StringToNumber<'1234'>;
|
|
12
|
+
//=> 1234
|
|
13
|
+
|
|
14
|
+
type NegativeInteger = StringToNumber<'-1234'>;
|
|
15
|
+
//=> -1234
|
|
16
|
+
|
|
17
|
+
type PositiveFloat = StringToNumber<'1234.56'>;
|
|
18
|
+
//=> 1234.56
|
|
19
|
+
|
|
20
|
+
type NegativeFloat = StringToNumber<'-1234.56'>;
|
|
21
|
+
//=> -1234.56
|
|
22
|
+
|
|
23
|
+
type PositiveInfinity = StringToNumber<'Infinity'>;
|
|
24
|
+
//=> Infinity
|
|
25
|
+
|
|
26
|
+
type NegativeInfinity = StringToNumber<'-Infinity'>;
|
|
27
|
+
//=> -Infinity
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Note: Some strings, such as `'1.50'`, `'0b10'`, or `'12_345'`, may look like they can be converted to numbers, but they don't actually have corresponding numeric literals. So, in such cases, this type produces `never`. See [type-fest#1446](https://github.com/sindresorhus/type-fest/pull/1446) for more details.
|
|
31
|
+
|
|
32
|
+
@example
|
|
33
|
+
```
|
|
34
|
+
import type {StringToNumber} from 'type-fest';
|
|
35
|
+
|
|
36
|
+
type FractionalsEndingInZero = StringToNumber<'1.50'>;
|
|
37
|
+
//=> never
|
|
38
|
+
|
|
39
|
+
type NonDecimalBases = StringToNumber<'0b10' | '0o10' | '0x10'>;
|
|
40
|
+
//=> never
|
|
41
|
+
|
|
42
|
+
type NumericSeparators = StringToNumber<'12_345'>;
|
|
43
|
+
//=> never
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
@category String
|
|
47
|
+
@category Numeric
|
|
48
|
+
@category Template literal
|
|
49
|
+
*/
|
|
50
|
+
export type StringToNumber<S extends string> = IfNotAnyOrNever<S, {ifNot: _StringToNumber<S>; ifAny: number}>;
|
|
51
|
+
|
|
52
|
+
type _StringToNumber<S extends string> =
|
|
53
|
+
S extends `${infer N extends number}`
|
|
54
|
+
? number extends N
|
|
55
|
+
? `${number}` extends S
|
|
56
|
+
? N
|
|
57
|
+
: never
|
|
58
|
+
: N
|
|
59
|
+
: string extends S
|
|
60
|
+
? number
|
|
61
|
+
: S extends 'Infinity'
|
|
62
|
+
? PositiveInfinity
|
|
63
|
+
: S extends '-Infinity'
|
|
64
|
+
? NegativeInfinity
|
|
65
|
+
: never;
|
|
66
|
+
|
|
67
|
+
export {};
|
package/source/subtract.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {ReverseSign} from './internal/index.d.ts';
|
|
2
2
|
import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric.d.ts';
|
|
3
3
|
import type {LessThan} from './less-than.d.ts';
|
|
4
4
|
import type {TupleOf} from './tuple-of.d.ts';
|
|
5
|
+
import type {Absolute} from './absolute.d.ts';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
Returns the difference between two numbers.
|
|
@@ -59,9 +60,9 @@ type SubtractPostChecks<A extends number, B extends number, AreNegative = [IsNeg
|
|
|
59
60
|
? SubtractPositives<A, B>
|
|
60
61
|
: AreNegative extends [true, true]
|
|
61
62
|
// When both numbers are negative we subtract the absolute values and then reverse the sign
|
|
62
|
-
? ReverseSign<SubtractPositives<
|
|
63
|
+
? ReverseSign<SubtractPositives<Absolute<A>, Absolute<B>>>
|
|
63
64
|
// When the signs are different we can add the absolute values and then reverse the sign if A < B
|
|
64
|
-
: [...TupleOf<
|
|
65
|
+
: [...TupleOf<Absolute<A>>, ...TupleOf<Absolute<B>>] extends infer R extends unknown[]
|
|
65
66
|
? LessThan<A, B> extends true ? ReverseSign<R['length']> : R['length']
|
|
66
67
|
: never;
|
|
67
68
|
|
package/source/sum.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type {TupleOf} from './tuple-of.d.ts';
|
|
2
|
-
import type {
|
|
2
|
+
import type {TupleMax, ReverseSign} from './internal/index.d.ts';
|
|
3
3
|
import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric.d.ts';
|
|
4
4
|
import type {Subtract} from './subtract.d.ts';
|
|
5
|
+
import type {Absolute} from './absolute.d.ts';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
Returns the sum of two numbers.
|
|
@@ -57,11 +58,11 @@ type SumPostChecks<A extends number, B extends number, AreNegative = [IsNegative
|
|
|
57
58
|
? SumPositives<A, B>
|
|
58
59
|
: AreNegative extends [true, true]
|
|
59
60
|
// When both numbers are negative we add the absolute values and then reverse the sign
|
|
60
|
-
? ReverseSign<SumPositives<
|
|
61
|
+
? ReverseSign<SumPositives<Absolute<A>, Absolute<B>>>
|
|
61
62
|
// When the signs are different we can subtract the absolute values, remove the sign
|
|
62
63
|
// and then reverse the sign if the larger absolute value is negative
|
|
63
|
-
:
|
|
64
|
-
? TupleMax<[
|
|
64
|
+
: Absolute<Subtract<Absolute<A>, Absolute<B>>> extends infer Result extends number
|
|
65
|
+
? TupleMax<[Absolute<A>, Absolute<B>]> extends infer Max_ extends number
|
|
65
66
|
? Max_ extends A | B
|
|
66
67
|
// The larger absolute value is positive, so the result is positive
|
|
67
68
|
? Result
|
package/source/tagged.d.ts
CHANGED
|
@@ -8,12 +8,10 @@ export type TagContainer<Token> = {
|
|
|
8
8
|
type Tag<Token extends PropertyKey, TagMetadata> = TagContainer<{[K in Token]: TagMetadata}>;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
|
|
11
|
+
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).
|
|
12
12
|
|
|
13
13
|
A type returned by `Tagged` can be passed to `Tagged` again, to create a type with multiple tags.
|
|
14
14
|
|
|
15
|
-
[Read more about tagged types.](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d)
|
|
16
|
-
|
|
17
15
|
A tag's name is usually a string (and must be a string, number, or symbol), but each application of a tag can also contain an arbitrary type as its "metadata". See {@link GetTagMetadata} for examples and explanation.
|
|
18
16
|
|
|
19
17
|
A type `A` returned by `Tagged` is assignable to another type `B` returned by `Tagged` if and only if:
|
|
@@ -100,7 +98,7 @@ const parsed = parse(x); // The type of `parsed` is { hello: string }
|
|
|
100
98
|
export type GetTagMetadata<Type extends Tag<TagName, unknown>, TagName extends PropertyKey> = Type[typeof tag][TagName];
|
|
101
99
|
|
|
102
100
|
/**
|
|
103
|
-
|
|
101
|
+
Get the untagged portion of a tagged type created with `Tagged`.
|
|
104
102
|
|
|
105
103
|
Why is this necessary?
|
|
106
104
|
|
|
@@ -129,7 +127,7 @@ type WontWork = UnwrapTagged<string>;
|
|
|
129
127
|
@category Type
|
|
130
128
|
*/
|
|
131
129
|
export type UnwrapTagged<TaggedType extends Tag<PropertyKey, any>> =
|
|
132
|
-
RemoveAllTags<TaggedType>;
|
|
130
|
+
RemoveAllTags<TaggedType>;
|
|
133
131
|
|
|
134
132
|
type RemoveAllTags<T> = T extends Tag<PropertyKey, any>
|
|
135
133
|
? {
|
|
@@ -61,6 +61,7 @@ export namespace TsConfigJson {
|
|
|
61
61
|
| 'ES2022'
|
|
62
62
|
| 'ES2023'
|
|
63
63
|
| 'ES2024'
|
|
64
|
+
| 'ES2025'
|
|
64
65
|
| 'ESNext'
|
|
65
66
|
// Lowercase alternatives
|
|
66
67
|
| 'es3'
|
|
@@ -76,6 +77,7 @@ export namespace TsConfigJson {
|
|
|
76
77
|
| 'es2022'
|
|
77
78
|
| 'es2023'
|
|
78
79
|
| 'es2024'
|
|
80
|
+
| 'es2025'
|
|
79
81
|
| 'esnext';
|
|
80
82
|
|
|
81
83
|
type Lib =
|
|
@@ -148,6 +150,13 @@ export namespace TsConfigJson {
|
|
|
148
150
|
| 'ES2024.Regexp'
|
|
149
151
|
| 'ES2024.SharedMemory'
|
|
150
152
|
| 'ES2024.String'
|
|
153
|
+
| 'ES2025'
|
|
154
|
+
| 'ES2025.Collection'
|
|
155
|
+
| 'ES2025.Float16'
|
|
156
|
+
| 'ES2025.Intl'
|
|
157
|
+
| 'ES2025.Iterator'
|
|
158
|
+
| 'ES2025.Promise'
|
|
159
|
+
| 'ES2025.RegExp'
|
|
151
160
|
| 'ESNext'
|
|
152
161
|
| 'ESNext.Array'
|
|
153
162
|
| 'ESNext.AsyncIterable'
|
|
@@ -156,6 +165,7 @@ export namespace TsConfigJson {
|
|
|
156
165
|
| 'ESNext.Decorators'
|
|
157
166
|
| 'ESNext.Disposable'
|
|
158
167
|
| 'ESNext.Error'
|
|
168
|
+
| 'ESNext.Float16'
|
|
159
169
|
| 'ESNext.Intl'
|
|
160
170
|
| 'ESNext.Iterator'
|
|
161
171
|
| 'ESNext.Object'
|
|
@@ -163,6 +173,7 @@ export namespace TsConfigJson {
|
|
|
163
173
|
| 'ESNext.Regexp'
|
|
164
174
|
| 'ESNext.String'
|
|
165
175
|
| 'ESNext.Symbol'
|
|
176
|
+
| 'ESNext.Temporal'
|
|
166
177
|
| 'ESNext.WeakRef'
|
|
167
178
|
| 'DOM'
|
|
168
179
|
| 'DOM.AsyncIterable'
|
|
@@ -244,6 +255,13 @@ export namespace TsConfigJson {
|
|
|
244
255
|
| 'es2024.regexp'
|
|
245
256
|
| 'es2024.sharedmemory'
|
|
246
257
|
| 'es2024.string'
|
|
258
|
+
| 'es2025'
|
|
259
|
+
| 'es2025.collection'
|
|
260
|
+
| 'es2025.float16'
|
|
261
|
+
| 'es2025.intl'
|
|
262
|
+
| 'es2025.iterator'
|
|
263
|
+
| 'es2025.promise'
|
|
264
|
+
| 'es2025.regexp'
|
|
247
265
|
| 'esnext'
|
|
248
266
|
| 'esnext.array'
|
|
249
267
|
| 'esnext.asynciterable'
|
|
@@ -252,6 +270,7 @@ export namespace TsConfigJson {
|
|
|
252
270
|
| 'esnext.decorators'
|
|
253
271
|
| 'esnext.disposable'
|
|
254
272
|
| 'esnext.error'
|
|
273
|
+
| 'esnext.float16'
|
|
255
274
|
| 'esnext.intl'
|
|
256
275
|
| 'esnext.iterator'
|
|
257
276
|
| 'esnext.object'
|
|
@@ -259,6 +278,7 @@ export namespace TsConfigJson {
|
|
|
259
278
|
| 'esnext.regexp'
|
|
260
279
|
| 'esnext.string'
|
|
261
280
|
| 'esnext.symbol'
|
|
281
|
+
| 'esnext.temporal'
|
|
262
282
|
| 'esnext.weakref'
|
|
263
283
|
| 'dom'
|
|
264
284
|
| 'dom.asynciterable'
|
|
@@ -326,7 +346,7 @@ export namespace TsConfigJson {
|
|
|
326
346
|
| 'legacy'
|
|
327
347
|
| 'force';
|
|
328
348
|
|
|
329
|
-
type IgnoreDeprecations = '5.0';
|
|
349
|
+
type IgnoreDeprecations = '5.0' | '6.0';
|
|
330
350
|
}
|
|
331
351
|
|
|
332
352
|
type CompilerOptions = {
|
|
@@ -479,7 +499,7 @@ export namespace TsConfigJson {
|
|
|
479
499
|
/**
|
|
480
500
|
Specify module code generation: 'None', 'CommonJS', 'AMD', 'System', 'UMD', 'ES6', 'ES2015' or 'ESNext'. Only 'AMD' and 'System' can be used in conjunction with `--outFile`. 'ES6' and 'ES2015' values may be used when targeting 'ES5' or lower.
|
|
481
501
|
|
|
482
|
-
|
|
502
|
+
Default: `'ESNext'` since TypeScript 6.0, `['ES3', 'ES5'].includes(target) ? 'CommonJS' : 'ES6'` before.
|
|
483
503
|
*/
|
|
484
504
|
module?: CompilerOptions.Module;
|
|
485
505
|
|
|
@@ -587,8 +607,17 @@ export namespace TsConfigJson {
|
|
|
587
607
|
*/
|
|
588
608
|
skipLibCheck?: boolean;
|
|
589
609
|
|
|
610
|
+
/**
|
|
611
|
+
Enforce stable type ordering.
|
|
612
|
+
|
|
613
|
+
@default false
|
|
614
|
+
*/
|
|
615
|
+
stableTypeOrdering?: boolean;
|
|
616
|
+
|
|
590
617
|
/**
|
|
591
618
|
Concatenate and emit output to single file.
|
|
619
|
+
|
|
620
|
+
@deprecated since TypeScript 6.0.
|
|
592
621
|
*/
|
|
593
622
|
outFile?: string;
|
|
594
623
|
|
|
@@ -696,7 +725,7 @@ export namespace TsConfigJson {
|
|
|
696
725
|
/**
|
|
697
726
|
Specify ECMAScript target version.
|
|
698
727
|
|
|
699
|
-
|
|
728
|
+
Default: Current-year ES version since TypeScript 6.0, `'es3'` before.
|
|
700
729
|
*/
|
|
701
730
|
target?: CompilerOptions.Target;
|
|
702
731
|
|
|
@@ -776,7 +805,7 @@ export namespace TsConfigJson {
|
|
|
776
805
|
/**
|
|
777
806
|
Report error if failed to find a source file for a side effect import.
|
|
778
807
|
|
|
779
|
-
|
|
808
|
+
Default: `true` since TypeScript 6.0, `false` before.
|
|
780
809
|
*/
|
|
781
810
|
noUncheckedSideEffectImports?: boolean;
|
|
782
811
|
|
|
@@ -822,6 +851,8 @@ export namespace TsConfigJson {
|
|
|
822
851
|
|
|
823
852
|
/**
|
|
824
853
|
Base directory to resolve non-relative module names.
|
|
854
|
+
|
|
855
|
+
@deprecated since TypeScript 6.0.
|
|
825
856
|
*/
|
|
826
857
|
baseUrl?: string;
|
|
827
858
|
|
|
@@ -944,7 +975,7 @@ export namespace TsConfigJson {
|
|
|
944
975
|
/**
|
|
945
976
|
Enable all strict type checking options.
|
|
946
977
|
|
|
947
|
-
|
|
978
|
+
Default: `true` since TypeScript 6.0, `false` before.
|
|
948
979
|
*/
|
|
949
980
|
strict?: boolean;
|
|
950
981
|
|
|
@@ -959,6 +990,7 @@ export namespace TsConfigJson {
|
|
|
959
990
|
Provide full support for iterables in `for-of`, spread, and destructuring when targeting `ES5` or `ES3`.
|
|
960
991
|
|
|
961
992
|
@default false
|
|
993
|
+
@deprecated since TypeScript 6.0.
|
|
962
994
|
*/
|
|
963
995
|
downlevelIteration?: boolean;
|
|
964
996
|
|
|
@@ -1150,7 +1182,7 @@ export namespace TsConfigJson {
|
|
|
1150
1182
|
/**
|
|
1151
1183
|
Enable lib replacement.
|
|
1152
1184
|
|
|
1153
|
-
|
|
1185
|
+
Default: `false` since TypeScript 6.0, `true` before.
|
|
1154
1186
|
*/
|
|
1155
1187
|
libReplacement?: boolean;
|
|
1156
1188
|
};
|
|
@@ -1234,7 +1266,7 @@ export namespace TsConfigJson {
|
|
|
1234
1266
|
exclude?: string[];
|
|
1235
1267
|
|
|
1236
1268
|
/**
|
|
1237
|
-
Disable
|
|
1269
|
+
Disable inferring what types should be added based on filenames in a project.
|
|
1238
1270
|
*/
|
|
1239
1271
|
disableFilenameBasedTypeAcquisition?: boolean;
|
|
1240
1272
|
};
|
|
@@ -1266,7 +1298,7 @@ export namespace TsConfigJson {
|
|
|
1266
1298
|
}
|
|
1267
1299
|
|
|
1268
1300
|
/**
|
|
1269
|
-
Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html)
|
|
1301
|
+
Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
|
|
1270
1302
|
|
|
1271
1303
|
@category File
|
|
1272
1304
|
*/
|
package/source/tuple-of.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {If} from './if.d.ts';
|
|
2
2
|
import type {IfNotAnyOrNever} from './internal/type.d.ts';
|
|
3
3
|
import type {IsNegative} from './numeric.d.ts';
|
|
4
|
+
import type {DigitCharacter} from './characters.d.ts';
|
|
4
5
|
import type {UnknownArray} from './unknown-array.d.ts';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -30,7 +31,7 @@ type ZeroToFour = Range<0, 5>;
|
|
|
30
31
|
//=> '0' | '1' | '2' | '3' | '4'
|
|
31
32
|
|
|
32
33
|
type ThreeToEight = Range<3, 9>;
|
|
33
|
-
//=> '
|
|
34
|
+
//=> '3' | '4' | '5' | '6' | '7' | '8'
|
|
34
35
|
```
|
|
35
36
|
|
|
36
37
|
Note: If the specified length is the non-literal `number` type, the result will not be a tuple but a regular array.
|
|
@@ -63,18 +64,51 @@ type EmptyTuple = TupleOf<-3, string>;
|
|
|
63
64
|
//=> []
|
|
64
65
|
```
|
|
65
66
|
|
|
67
|
+
Note: If the specified length has a decimal part, the decimal part will be ignored.
|
|
68
|
+
|
|
69
|
+
@example
|
|
70
|
+
```
|
|
71
|
+
import type {TupleOf} from 'type-fest';
|
|
72
|
+
|
|
73
|
+
type DecimalLength = TupleOf<3.5, string>;
|
|
74
|
+
//=> [string, string, string]
|
|
75
|
+
```
|
|
76
|
+
|
|
66
77
|
Note: If you need a readonly tuple, simply wrap this type with `Readonly`, for example, to create `readonly [number, number, number]` use `Readonly<TupleOf<3, number>>`.
|
|
67
78
|
|
|
68
79
|
@category Array
|
|
69
80
|
*/
|
|
70
|
-
export type TupleOf<Length extends number, Fill = unknown> = IfNotAnyOrNever<Length,
|
|
71
|
-
_TupleOf<If<IsNegative<Length>, 0, Length>, Fill
|
|
72
|
-
Fill[]
|
|
81
|
+
export type TupleOf<Length extends number, Fill = unknown> = IfNotAnyOrNever<Length, {
|
|
82
|
+
ifNot: _TupleOf<If<IsNegative<Length>, 0, Length>, Fill>;
|
|
83
|
+
ifAny: Fill[];
|
|
84
|
+
ifNever: [];
|
|
85
|
+
}>;
|
|
73
86
|
|
|
74
|
-
type _TupleOf<
|
|
87
|
+
type _TupleOf<Length extends number, Fill> = number extends Length
|
|
75
88
|
? Fill[]
|
|
76
|
-
:
|
|
77
|
-
|
|
78
|
-
|
|
89
|
+
: BuildTupleDigitByDigit<`${Length}`, Fill>;
|
|
90
|
+
|
|
91
|
+
type BuildTupleDigitByDigit<Length extends string, Fill, Accumulator extends UnknownArray = []> =
|
|
92
|
+
Length extends `${infer First extends DigitCharacter}${infer Rest}`
|
|
93
|
+
? BuildTupleDigitByDigit<Rest, Fill, [...RepeatTupleTenTimes<Accumulator>, ...DigitTupleOf<First, Fill>]>
|
|
94
|
+
: Accumulator;
|
|
95
|
+
|
|
96
|
+
type RepeatTupleTenTimes<Tuple extends UnknownArray> = [
|
|
97
|
+
...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple,
|
|
98
|
+
...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple,
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
type DigitTupleOf<Digit extends DigitCharacter, Fill> = [
|
|
102
|
+
[],
|
|
103
|
+
[Fill],
|
|
104
|
+
[Fill, Fill],
|
|
105
|
+
[Fill, Fill, Fill],
|
|
106
|
+
[Fill, Fill, Fill, Fill],
|
|
107
|
+
[Fill, Fill, Fill, Fill, Fill],
|
|
108
|
+
[Fill, Fill, Fill, Fill, Fill, Fill],
|
|
109
|
+
[Fill, Fill, Fill, Fill, Fill, Fill, Fill],
|
|
110
|
+
[Fill, Fill, Fill, Fill, Fill, Fill, Fill, Fill],
|
|
111
|
+
[Fill, Fill, Fill, Fill, Fill, Fill, Fill, Fill, Fill],
|
|
112
|
+
][Digit];
|
|
79
113
|
|
|
80
114
|
export {};
|
package/source/typed-array.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import type {FindGlobalType} from './find-global-type.d.ts';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
|
3
5
|
|
|
6
|
+
`Float16Array` is included only when it exists in your TypeScript `lib` (`ESNext` or `ES2025` and later).
|
|
7
|
+
|
|
4
8
|
@category Array
|
|
5
9
|
*/
|
|
6
10
|
export type TypedArray =
|
|
@@ -11,6 +15,8 @@ export type TypedArray =
|
|
|
11
15
|
| Uint16Array
|
|
12
16
|
| Int32Array
|
|
13
17
|
| Uint32Array
|
|
18
|
+
// Looked up through `globalThis` so that a `lib` without `Float16Array` gets `never` here instead of a compile error. The `prototype` type is `Float16Array<ArrayBufferLike>`, matching the other members.
|
|
19
|
+
| FindGlobalType<'Float16Array'>['prototype']
|
|
14
20
|
| Float32Array
|
|
15
21
|
| Float64Array
|
|
16
22
|
| BigInt64Array
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type {UnionToTuple} from './union-to-tuple.d.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Returns the length of a union type.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {UnionLength} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
type T1 = UnionLength<'foo' | 'bar' | 'baz'>;
|
|
11
|
+
//=> 3
|
|
12
|
+
|
|
13
|
+
type T2 = UnionLength<[string, string, string] | {x: string; y: string; z: string}>;
|
|
14
|
+
//=> 2
|
|
15
|
+
|
|
16
|
+
type T3 = UnionLength<any>;
|
|
17
|
+
//=> 1
|
|
18
|
+
|
|
19
|
+
type T4 = UnionLength<never>;
|
|
20
|
+
//=> 0
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
@category Type
|
|
24
|
+
*/
|
|
25
|
+
export type UnionLength<Union> = UnionToTuple<Union>['length'];
|
|
26
|
+
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type {IsNever} from './is-never.d.ts';
|
|
2
|
+
import type {Finite, NegativeInfinity, PositiveInfinity} from './numeric.d.ts';
|
|
3
|
+
import type {UnknownArray} from './unknown-array.d.ts';
|
|
4
|
+
import type {IsAnyOrNever} from './internal/type.d.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
Returns the maximum number in a union of numbers.
|
|
8
|
+
|
|
9
|
+
Use this to derive a maximum retry count or concurrency limit from a fixed set of supported values.
|
|
10
|
+
|
|
11
|
+
Supports small non-negative integer literals, plus `PositiveInfinity` and `NegativeInfinity`. Negative finite numbers and fractional numbers are not supported. Large integers or unions can exceed TypeScript’s recursion limit.
|
|
12
|
+
|
|
13
|
+
Returns `number`, `any`, or `never` when given those types.
|
|
14
|
+
|
|
15
|
+
@example
|
|
16
|
+
```
|
|
17
|
+
import type {UnionMax} from 'type-fest';
|
|
18
|
+
|
|
19
|
+
const retryCounts = [0, 2, 5] as const;
|
|
20
|
+
type MaximumRetries = UnionMax<typeof retryCounts[number]>;
|
|
21
|
+
//=> 5
|
|
22
|
+
|
|
23
|
+
const maximumRetries: MaximumRetries = 5;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
@example
|
|
27
|
+
```
|
|
28
|
+
import type {PositiveInfinity, UnionMax} from 'type-fest';
|
|
29
|
+
|
|
30
|
+
type Unlimited = UnionMax<1 | 5 | PositiveInfinity>;
|
|
31
|
+
//=> Infinity
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The implementation counts upward using a tuple, removing each matching union member until none remain. Infinity and non-literal inputs are handled before counting.
|
|
35
|
+
|
|
36
|
+
@see https://github.com/sindresorhus/type-fest/issues/676
|
|
37
|
+
@category Numeric
|
|
38
|
+
*/
|
|
39
|
+
export type UnionMax<NumberUnion extends number> =
|
|
40
|
+
IsAnyOrNever<NumberUnion> extends true ? NumberUnion
|
|
41
|
+
: number extends NumberUnion ? number
|
|
42
|
+
: PositiveInfinity extends NumberUnion ? PositiveInfinity
|
|
43
|
+
: [NumberUnion] extends [NegativeInfinity] ? NegativeInfinity
|
|
44
|
+
: InternalUnionMax<Finite<NumberUnion>>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
The actual implementation of `UnionMax`. It's private because it has some arguments that don't need to be exposed.
|
|
48
|
+
*/
|
|
49
|
+
type InternalUnionMax<NumberUnion extends number, Counter extends UnknownArray = []> =
|
|
50
|
+
IsNever<NumberUnion> extends true
|
|
51
|
+
? Counter['length']
|
|
52
|
+
: Counter['length'] extends NumberUnion
|
|
53
|
+
? InternalUnionMax<Exclude<NumberUnion, Counter['length']>, Counter>
|
|
54
|
+
: InternalUnionMax<NumberUnion, [...Counter, unknown]>;
|
|
55
|
+
|
|
56
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
Convert a union type to an intersection type
|
|
2
|
+
Convert a union type to an intersection type.
|
|
3
3
|
|
|
4
4
|
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
5
5
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {ExcludeExactly} from './exclude-exactly.d.ts';
|
|
2
2
|
import type {IsNever} from './is-never.d.ts';
|
|
3
3
|
import type {UnionMember} from './union-member.d.ts';
|
|
4
|
+
import type {UnknownArray} from './unknown-array.d.ts';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
Convert a union type into an unordered tuple type of its elements.
|
|
@@ -37,9 +38,12 @@ const petList = Object.keys(pets) as UnionToTuple<Pet>;
|
|
|
37
38
|
|
|
38
39
|
@category Array
|
|
39
40
|
*/
|
|
40
|
-
export type UnionToTuple<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
export type UnionToTuple<Union> =
|
|
42
|
+
_UnionToTuple<Union> extends infer Result extends UnknownArray ? Result : never; // Nudges the compiler that `UnionToTuple` always yields an array.
|
|
43
|
+
|
|
44
|
+
type _UnionToTuple<Union, Accumulator extends UnknownArray = [], Member = UnionMember<Union>> =
|
|
45
|
+
IsNever<Union> extends true
|
|
46
|
+
? Accumulator
|
|
47
|
+
: _UnionToTuple<ExcludeExactly<Union, Member>, [Member, ...Accumulator]>;
|
|
44
48
|
|
|
45
49
|
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type {MapsSetsOrArrays, NonRecursiveType} from './internal/type.d.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Revert the `Required` modifier on an object type.
|
|
5
|
+
|
|
6
|
+
Use-case: Infer the underlying type `T` when only `Required<T>` is available or the original type may not be directly accessible.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {UnwrapRequired} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type ContactFormData = Required<{
|
|
13
|
+
email: string;
|
|
14
|
+
message?: string;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
type DraftContactFormData = UnwrapRequired<ContactFormData>;
|
|
18
|
+
//=> {email: string; message?: string}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Note:
|
|
22
|
+
- If the provided type isn’t of the form `Required<T>`, `UnwrapRequired` simply returns the input type.
|
|
23
|
+
- `UnwrapRequired` doesn't work with arrays, if instantiated with arrays, it simply returns the input type.
|
|
24
|
+
|
|
25
|
+
@category Object
|
|
26
|
+
*/
|
|
27
|
+
export type UnwrapRequired<RequiredObjectType> =
|
|
28
|
+
RequiredObjectType extends NonRecursiveType | MapsSetsOrArrays
|
|
29
|
+
? RequiredObjectType
|
|
30
|
+
: _UnwrapRequired<RequiredObjectType>;
|
|
31
|
+
|
|
32
|
+
type _UnwrapRequired<RequiredObjectType> =
|
|
33
|
+
RequiredObjectType extends Required<infer ObjectType>
|
|
34
|
+
? ObjectType
|
|
35
|
+
: RequiredObjectType;
|
|
36
|
+
|
|
37
|
+
export {};
|