type-fest 5.0.0 → 5.1.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 +17 -12
- package/package.json +2 -1
- package/readme.md +18 -10
- package/source/all-extend.d.ts +3 -1
- package/source/all-union-fields.d.ts +2 -0
- package/source/and.d.ts +2 -0
- package/source/array-indices.d.ts +2 -0
- package/source/array-slice.d.ts +2 -0
- package/source/array-splice.d.ts +7 -4
- package/source/array-tail.d.ts +3 -1
- package/source/array-values.d.ts +2 -0
- package/source/arrayable.d.ts +2 -0
- package/source/async-return-type.d.ts +2 -0
- package/source/asyncify.d.ts +2 -0
- package/source/basic.d.ts +2 -0
- package/source/camel-case.d.ts +4 -2
- package/source/camel-cased-properties-deep.d.ts +4 -2
- package/source/camel-cased-properties.d.ts +4 -2
- package/source/characters.d.ts +2 -0
- package/source/conditional-except.d.ts +2 -0
- package/source/conditional-keys.d.ts +2 -0
- package/source/conditional-pick-deep.d.ts +2 -0
- package/source/conditional-pick.d.ts +2 -0
- package/source/conditional-simplify-deep.d.ts +2 -0
- package/source/conditional-simplify.d.ts +2 -0
- package/source/delimiter-case.d.ts +5 -3
- package/source/delimiter-cased-properties-deep.d.ts +4 -2
- package/source/delimiter-cased-properties.d.ts +4 -2
- package/source/distributed-omit.d.ts +2 -0
- package/source/distributed-pick.d.ts +2 -0
- package/source/empty-object.d.ts +2 -0
- package/source/entries.d.ts +7 -5
- package/source/entry.d.ts +10 -8
- package/source/exact.d.ts +2 -0
- package/source/except.d.ts +3 -1
- package/source/exclude-rest-element.d.ts +37 -0
- package/source/exclude-strict.d.ts +2 -0
- package/source/extends-strict.d.ts +2 -0
- package/source/extract-rest-element.d.ts +29 -0
- package/source/extract-strict.d.ts +2 -0
- package/source/find-global-type.d.ts +2 -0
- package/source/fixed-length-array.d.ts +67 -21
- package/source/get.d.ts +5 -3
- package/source/global-this.d.ts +2 -0
- package/source/globals/index.d.ts +2 -0
- package/source/globals/observable-like.d.ts +5 -0
- package/source/greater-than-or-equal.d.ts +2 -0
- package/source/greater-than.d.ts +2 -0
- package/source/has-optional-keys.d.ts +2 -0
- package/source/has-readonly-keys.d.ts +2 -0
- package/source/has-required-keys.d.ts +2 -0
- package/source/has-writable-keys.d.ts +2 -0
- package/source/if-any.d.ts +2 -0
- package/source/if-empty-object.d.ts +2 -0
- package/source/if-never.d.ts +2 -0
- package/source/if-null.d.ts +2 -0
- package/source/if-unknown.d.ts +2 -0
- package/source/if.d.ts +2 -0
- package/source/includes.d.ts +2 -0
- package/source/int-closed-range.d.ts +2 -0
- package/source/int-range.d.ts +7 -5
- package/source/internal/array.d.ts +2 -0
- package/source/internal/characters.d.ts +2 -0
- package/source/{enforce-optional.d.ts → internal/enforce-optional.d.ts} +3 -1
- package/source/internal/index.d.ts +3 -0
- package/source/internal/keys.d.ts +2 -0
- package/source/internal/numeric.d.ts +2 -0
- package/source/internal/object.d.ts +2 -0
- package/source/internal/string.d.ts +4 -2
- package/source/internal/tuple.d.ts +2 -13
- package/source/internal/type.d.ts +2 -0
- package/source/invariant-of.d.ts +2 -0
- package/source/is-any.d.ts +2 -0
- package/source/is-equal.d.ts +15 -0
- package/source/is-float.d.ts +2 -0
- package/source/is-integer.d.ts +2 -0
- package/source/is-literal.d.ts +4 -2
- package/source/is-lowercase.d.ts +2 -0
- package/source/is-never.d.ts +2 -0
- package/source/is-null.d.ts +2 -0
- package/source/is-nullable.d.ts +2 -0
- package/source/is-optional-key-of.d.ts +2 -0
- package/source/is-optional.d.ts +2 -0
- package/source/is-readonly-key-of.d.ts +2 -0
- package/source/is-required-key-of.d.ts +2 -0
- package/source/is-tuple.d.ts +2 -0
- package/source/is-undefined.d.ts +2 -0
- package/source/is-union.d.ts +2 -0
- package/source/is-unknown.d.ts +2 -0
- package/source/is-uppercase.d.ts +2 -0
- package/source/is-writable-key-of.d.ts +2 -0
- package/source/iterable-element.d.ts +2 -0
- package/source/join.d.ts +2 -0
- package/source/json-value.d.ts +3 -1
- package/source/jsonifiable.d.ts +2 -0
- package/source/jsonify.d.ts +2 -0
- package/source/kebab-case.d.ts +4 -2
- package/source/kebab-cased-properties-deep.d.ts +4 -2
- package/source/kebab-cased-properties.d.ts +4 -2
- package/source/key-as-string.d.ts +2 -0
- package/source/keys-of-union.d.ts +2 -0
- package/source/last-array-element.d.ts +3 -1
- package/source/less-than-or-equal.d.ts +2 -0
- package/source/less-than.d.ts +2 -0
- package/source/literal-to-primitive-deep.d.ts +2 -0
- package/source/literal-to-primitive.d.ts +2 -0
- package/source/literal-union.d.ts +3 -1
- package/source/merge-deep.d.ts +3 -1
- package/source/merge-exclusive.d.ts +1 -0
- package/source/merge.d.ts +2 -0
- package/source/multidimensional-array.d.ts +2 -0
- package/source/multidimensional-readonly-array.d.ts +2 -0
- package/source/non-empty-object.d.ts +2 -0
- package/source/non-empty-string.d.ts +2 -0
- package/source/non-empty-tuple.d.ts +2 -0
- package/source/numeric.d.ts +7 -5
- package/source/omit-deep.d.ts +2 -0
- package/source/omit-index-signature.d.ts +2 -0
- package/source/opaque.d.ts +2 -0
- package/source/optional-keys-of.d.ts +2 -0
- package/source/or.d.ts +2 -0
- package/source/override-properties.d.ts +2 -0
- package/source/package-json.d.ts +18 -16
- package/source/partial-deep.d.ts +20 -17
- package/source/partial-on-undefined-deep.d.ts +2 -0
- package/source/pascal-case.d.ts +5 -3
- package/source/pascal-cased-properties-deep.d.ts +4 -2
- package/source/pascal-cased-properties.d.ts +4 -2
- package/source/paths.d.ts +2 -0
- package/source/pick-deep.d.ts +8 -5
- package/source/pick-index-signature.d.ts +2 -0
- package/source/primitive.d.ts +2 -0
- package/source/promisable.d.ts +2 -0
- package/source/readonly-deep.d.ts +6 -4
- package/source/readonly-keys-of.d.ts +2 -0
- package/source/readonly-tuple.d.ts +6 -15
- package/source/remove-prefix.d.ts +4 -2
- package/source/replace.d.ts +3 -1
- package/source/require-all-or-none.d.ts +2 -0
- package/source/require-at-least-one.d.ts +2 -0
- package/source/require-exactly-one.d.ts +2 -0
- package/source/require-one-or-none.d.ts +2 -0
- package/source/required-deep.d.ts +4 -1
- package/source/required-keys-of.d.ts +2 -0
- package/source/schema.d.ts +2 -0
- package/source/screaming-snake-case.d.ts +4 -2
- package/source/set-field-type.d.ts +3 -1
- package/source/set-non-nullable-deep.d.ts +2 -0
- package/source/set-non-nullable.d.ts +2 -0
- package/source/set-optional.d.ts +2 -0
- package/source/set-parameter-type.d.ts +2 -0
- package/source/set-readonly.d.ts +2 -0
- package/source/set-required-deep.d.ts +2 -0
- package/source/set-required.d.ts +2 -0
- package/source/set-return-type.d.ts +2 -0
- package/source/shared-union-fields-deep.d.ts +2 -0
- package/source/shared-union-fields.d.ts +2 -0
- package/source/simplify-deep.d.ts +2 -0
- package/source/simplify.d.ts +2 -0
- package/source/single-key-object.d.ts +2 -0
- package/source/snake-case.d.ts +4 -2
- package/source/snake-cased-properties-deep.d.ts +4 -2
- package/source/snake-cased-properties.d.ts +4 -2
- package/source/split-on-rest-element.d.ts +106 -0
- package/source/split.d.ts +3 -1
- package/source/spread.d.ts +2 -0
- package/source/string-repeat.d.ts +2 -0
- package/source/string-slice.d.ts +2 -0
- package/source/stringified.d.ts +2 -0
- package/source/structured-cloneable.d.ts +2 -0
- package/source/subtract.d.ts +6 -3
- package/source/sum.d.ts +5 -2
- package/source/tagged-union.d.ts +2 -0
- package/source/tagged.d.ts +3 -0
- package/source/trim.d.ts +2 -0
- package/source/tsconfig-json.d.ts +54 -25
- package/source/tuple-of.d.ts +78 -0
- package/source/tuple-to-object.d.ts +2 -0
- package/source/tuple-to-union.d.ts +2 -0
- package/source/typed-array.d.ts +2 -0
- package/source/undefined-on-partial-deep.d.ts +2 -0
- package/source/union-to-intersection.d.ts +3 -1
- package/source/union-to-tuple.d.ts +2 -0
- package/source/unknown-array.d.ts +2 -0
- package/source/unknown-map.d.ts +2 -0
- package/source/unknown-record.d.ts +2 -0
- package/source/unknown-set.d.ts +2 -0
- package/source/value-of.d.ts +2 -0
- package/source/words.d.ts +4 -2
- package/source/writable-deep.d.ts +5 -4
- package/source/writable-keys-of.d.ts +2 -0
- package/source/writable.d.ts +2 -0
- package/source/xor.d.ts +83 -0
|
@@ -41,11 +41,11 @@ export type ReadonlyDeep<T> = T extends BuiltIns
|
|
|
41
41
|
: T extends new (...arguments_: any[]) => unknown
|
|
42
42
|
? T // Skip class constructors
|
|
43
43
|
: T extends (...arguments_: any[]) => unknown
|
|
44
|
-
? {} extends
|
|
44
|
+
? {} extends _ReadonlyObjectDeep<T>
|
|
45
45
|
? T
|
|
46
46
|
: HasMultipleCallSignatures<T> extends true
|
|
47
47
|
? T
|
|
48
|
-
: ((...arguments_: Parameters<T>) => ReturnType<T>) &
|
|
48
|
+
: ((...arguments_: Parameters<T>) => ReturnType<T>) & _ReadonlyObjectDeep<T>
|
|
49
49
|
: T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>>
|
|
50
50
|
? ReadonlyMapDeep<KeyType, ValueType>
|
|
51
51
|
: T extends Readonly<ReadonlySet<infer ItemType>>
|
|
@@ -60,7 +60,7 @@ export type ReadonlyDeep<T> = T extends BuiltIns
|
|
|
60
60
|
: T extends ReadonlyArray<infer ItemType>
|
|
61
61
|
? ReadonlyArray<ReadonlyDeep<ItemType>>
|
|
62
62
|
: T extends object
|
|
63
|
-
?
|
|
63
|
+
? _ReadonlyObjectDeep<T>
|
|
64
64
|
: unknown;
|
|
65
65
|
|
|
66
66
|
/**
|
|
@@ -76,6 +76,8 @@ type ReadonlySetDeep<ItemType> = {} & Readonly<ReadonlySet<ReadonlyDeep<ItemType
|
|
|
76
76
|
/**
|
|
77
77
|
Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
78
78
|
*/
|
|
79
|
-
type
|
|
79
|
+
export type _ReadonlyObjectDeep<ObjectType extends object> = {
|
|
80
80
|
readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
|
|
81
81
|
};
|
|
82
|
+
|
|
83
|
+
export {};
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Creates a read-only tuple of type `Element` and with the length of `Length`.
|
|
3
|
-
|
|
4
|
-
@private
|
|
5
|
-
@see `ReadonlyTuple` which is safer because it tests if `Length` is a specific finite number.
|
|
6
|
-
*/
|
|
7
|
-
type BuildTupleHelper<Element, Length extends number, Rest extends Element[]> =
|
|
8
|
-
Rest['length'] extends Length ?
|
|
9
|
-
readonly [...Rest] : // Terminate with readonly array (aka tuple)
|
|
10
|
-
BuildTupleHelper<Element, Length, [Element, ...Rest]>;
|
|
1
|
+
import type {TupleOf} from './tuple-of.d.ts';
|
|
11
2
|
|
|
12
3
|
/**
|
|
13
4
|
Create a type that represents a read-only tuple of the given type and length.
|
|
@@ -32,10 +23,10 @@ guestFencingTeam.push('Sam');
|
|
|
32
23
|
//=> error TS2339: Property 'push' does not exist on type 'FencingTeam'
|
|
33
24
|
```
|
|
34
25
|
|
|
26
|
+
@deprecated This type will be removed in the next major version. Use the built-in `Readonly` type in combination with the {@link TupleOf} type instead, like `Readonly<TupleOf<Length, Element>>`.
|
|
27
|
+
|
|
35
28
|
@category Utilities
|
|
36
29
|
*/
|
|
37
|
-
export type ReadonlyTuple<Element, Length extends number> =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
? readonly Element[] // It's not fixed length.
|
|
41
|
-
: BuildTupleHelper<Element, Length, []>; // Otherwise it is a fixed length tuple.
|
|
30
|
+
export type ReadonlyTuple<Element, Length extends number> = Readonly<TupleOf<Length, Element>>;
|
|
31
|
+
|
|
32
|
+
export {};
|
|
@@ -6,7 +6,7 @@ import type {Or} from './or.d.ts';
|
|
|
6
6
|
/**
|
|
7
7
|
@see {@link RemovePrefix}
|
|
8
8
|
*/
|
|
9
|
-
type RemovePrefixOptions = {
|
|
9
|
+
export type RemovePrefixOptions = {
|
|
10
10
|
/**
|
|
11
11
|
When enabled, instantiations with non-literal prefixes (e.g., `string`, `Uppercase<string>`, `` `on${string}` ``) simply return `string`, since their precise structure cannot be statically determined.
|
|
12
12
|
|
|
@@ -83,7 +83,7 @@ type DefaultRemovePrefixOptions = {
|
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
|
|
86
|
+
Remove the specified prefix from the start of a string.
|
|
87
87
|
|
|
88
88
|
@example
|
|
89
89
|
```
|
|
@@ -126,3 +126,5 @@ Prefix extends string // For distributing `Prefix`
|
|
|
126
126
|
: string // Fallback to `string` when `Prefix` is non-literal and `strict` is disabled
|
|
127
127
|
: S // Return back `S` when `Prefix` is not present at the start of `S`
|
|
128
128
|
: never;
|
|
129
|
+
|
|
130
|
+
export {};
|
package/source/replace.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {BuiltIns, HasMultipleCallSignatures} from './internal/index.d.ts';
|
|
2
|
+
import type {IsNever} from './is-never.d.ts';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
Create a type from another type with all keys and nested keys set to required.
|
|
@@ -58,7 +59,7 @@ export type RequiredDeep<T> = T extends BuiltIns
|
|
|
58
59
|
: T extends Promise<infer ValueType>
|
|
59
60
|
? Promise<RequiredDeep<ValueType>>
|
|
60
61
|
: T extends (...arguments_: any[]) => unknown
|
|
61
|
-
?
|
|
62
|
+
? IsNever<keyof T> extends true
|
|
62
63
|
? T
|
|
63
64
|
: HasMultipleCallSignatures<T> extends true
|
|
64
65
|
? T
|
|
@@ -70,3 +71,5 @@ export type RequiredDeep<T> = T extends BuiltIns
|
|
|
70
71
|
type RequiredObjectDeep<ObjectType extends object> = {
|
|
71
72
|
[KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]>
|
|
72
73
|
};
|
|
74
|
+
|
|
75
|
+
export {};
|
package/source/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {_DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
|
|
2
2
|
import type {ApplyDefaultOptions} from './internal/index.d.ts';
|
|
3
3
|
import type {SnakeCase} from './snake-case.d.ts';
|
|
4
4
|
import type {WordsOptions} from './words.d.ts';
|
|
@@ -24,5 +24,7 @@ export type ScreamingSnakeCase<
|
|
|
24
24
|
Value,
|
|
25
25
|
Options extends WordsOptions = {},
|
|
26
26
|
> = Value extends string
|
|
27
|
-
? Uppercase<SnakeCase<Value, ApplyDefaultOptions<WordsOptions,
|
|
27
|
+
? Uppercase<SnakeCase<Value, ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>>
|
|
28
28
|
: Value;
|
|
29
|
+
|
|
30
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {ApplyDefaultOptions} from './internal/index.d.ts';
|
|
2
2
|
import type {Simplify} from './simplify.d.ts';
|
|
3
3
|
|
|
4
|
-
type SetFieldTypeOptions = {
|
|
4
|
+
export type SetFieldTypeOptions = {
|
|
5
5
|
/**
|
|
6
6
|
Preserve optional and readonly modifiers for properties being updated.
|
|
7
7
|
|
|
@@ -63,3 +63,5 @@ type _SetFieldType<BaseType, Keys extends keyof BaseType, NewType, Options exten
|
|
|
63
63
|
// `Record` is used to remove property modifiers
|
|
64
64
|
Options['preservePropertyModifiers'] extends false ? Record<Keys, NewType> : unknown
|
|
65
65
|
)>;
|
|
66
|
+
|
|
67
|
+
export {};
|
package/source/set-optional.d.ts
CHANGED
package/source/set-readonly.d.ts
CHANGED
package/source/set-required.d.ts
CHANGED
package/source/simplify.d.ts
CHANGED
package/source/snake-case.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {_DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case.d.ts';
|
|
2
2
|
import type {ApplyDefaultOptions} from './internal/index.d.ts';
|
|
3
3
|
import type {WordsOptions} from './words.d.ts';
|
|
4
4
|
|
|
@@ -42,4 +42,6 @@ const dbResult: SnakeCasedProperties<ModelProps> = {
|
|
|
42
42
|
export type SnakeCase<
|
|
43
43
|
Value,
|
|
44
44
|
Options extends WordsOptions = {},
|
|
45
|
-
> = DelimiterCase<Value, '_', ApplyDefaultOptions<WordsOptions,
|
|
45
|
+
> = DelimiterCase<Value, '_', ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>;
|
|
46
|
+
|
|
47
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {_DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
|
|
2
2
|
import type {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep.d.ts';
|
|
3
3
|
import type {ApplyDefaultOptions} from './internal/index.d.ts';
|
|
4
4
|
import type {WordsOptions} from './words.d.ts';
|
|
@@ -60,4 +60,6 @@ const splitOnNumbers: SnakeCasedPropertiesDeep<{line1: { line2: [{ line3: string
|
|
|
60
60
|
export type SnakeCasedPropertiesDeep<
|
|
61
61
|
Value,
|
|
62
62
|
Options extends WordsOptions = {},
|
|
63
|
-
> = DelimiterCasedPropertiesDeep<Value, '_', ApplyDefaultOptions<WordsOptions,
|
|
63
|
+
> = DelimiterCasedPropertiesDeep<Value, '_', ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>;
|
|
64
|
+
|
|
65
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {_DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
|
|
2
2
|
import type {DelimiterCasedProperties} from './delimiter-cased-properties.d.ts';
|
|
3
3
|
import type {ApplyDefaultOptions} from './internal/index.d.ts';
|
|
4
4
|
import type {WordsOptions} from './words.d.ts';
|
|
@@ -37,4 +37,6 @@ const splitOnNumbers: SnakeCasedProperties<{line1: string}, {splitOnNumbers: tru
|
|
|
37
37
|
export type SnakeCasedProperties<
|
|
38
38
|
Value,
|
|
39
39
|
Options extends WordsOptions = {},
|
|
40
|
-
> = DelimiterCasedProperties<Value, '_', ApplyDefaultOptions<WordsOptions,
|
|
40
|
+
> = DelimiterCasedProperties<Value, '_', ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>;
|
|
41
|
+
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type {IfNotAnyOrNever, IsExactOptionalPropertyTypesEnabled} from './internal/type.d.ts';
|
|
2
|
+
import type {ApplyDefaultOptions} from './internal/object.d.ts';
|
|
3
|
+
import type {IsOptionalKeyOf} from './is-optional-key-of.d.ts';
|
|
4
|
+
import type {IsArrayReadonly} from './internal/array.d.ts';
|
|
5
|
+
import type {UnknownArray} from './unknown-array.d.ts';
|
|
6
|
+
import type {If} from './if.d.ts';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
{@link SplitOnRestElement} options.
|
|
10
|
+
*/
|
|
11
|
+
type SplitOnRestElementOptions = {
|
|
12
|
+
/**
|
|
13
|
+
Whether to preserve the optional modifier (`?`).
|
|
14
|
+
|
|
15
|
+
- When set to `true`, the optional modifiers are preserved as-is. For example:
|
|
16
|
+
`SplitOnRestElement<[number, string?, ...boolean[]], {preserveOptionalModifier: true}>` returns `[[number, string?], boolean[], []]`.
|
|
17
|
+
|
|
18
|
+
- When set to `false`, optional elements like `T?` are transformed to `T | undefined` or simply `T` depending on the `exactOptionalPropertyTypes` compiler option. For example:
|
|
19
|
+
- With `exactOptionalPropertyTypes` enabled: `SplitOnRestElement<[number, string?, ...boolean[]], {preserveOptionalModifier: false}>` returns `[[number, string], boolean[], []]`
|
|
20
|
+
- And, with it disabled, the result is: `[[number, string | undefined], boolean[], []]`
|
|
21
|
+
|
|
22
|
+
@default true
|
|
23
|
+
*/
|
|
24
|
+
preserveOptionalModifier?: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type DefaultSplitOnRestElementOptions = {
|
|
28
|
+
preserveOptionalModifier: true;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
Splits an array into three parts, where the first contains all elements before the rest element, the second is the [`rest`](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) element itself, and the third contains all elements after the rest element.
|
|
33
|
+
|
|
34
|
+
Note: If any of the parts are missing, then they will be represented as empty arrays. For example, `SplitOnRestElement<[string, number]>` returns `[[string, number], [], []]`, where parts corresponding to the rest element and elements after it are empty.
|
|
35
|
+
|
|
36
|
+
By default, the optional modifier (`?`) is preserved.
|
|
37
|
+
See {@link SplitOnRestElementOptions `SplitOnRestElementOptions`}.
|
|
38
|
+
|
|
39
|
+
@example
|
|
40
|
+
```ts
|
|
41
|
+
import type {SplitOnRestElement} from 'type-fest';
|
|
42
|
+
|
|
43
|
+
type T1 = SplitOnRestElement<[number, ...string[], boolean]>;
|
|
44
|
+
//=> [[number], string[], [boolean]]
|
|
45
|
+
|
|
46
|
+
type T2 = SplitOnRestElement<readonly [...boolean[], string]>;
|
|
47
|
+
//=> readonly [[], boolean[], [string]]
|
|
48
|
+
|
|
49
|
+
type T3 = SplitOnRestElement<[number, string?]>;
|
|
50
|
+
//=> [[number, string?], [], []]
|
|
51
|
+
|
|
52
|
+
type T4 = SplitOnRestElement<[number, string?], {preserveOptionalModifier: false}>;
|
|
53
|
+
//=> [[number, string], [], []] or [[number, string | undefined], [], []]
|
|
54
|
+
|
|
55
|
+
type T5 = SplitOnRestElement<readonly [string?, ...number[]], {preserveOptionalModifier: false}>;
|
|
56
|
+
//=> readonly [[string], number[], []] or readonly [[string | undefined], number[], []]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
@see ExtractRestElement
|
|
60
|
+
@see ExcludeRestElement
|
|
61
|
+
@category Array
|
|
62
|
+
*/
|
|
63
|
+
export type SplitOnRestElement<
|
|
64
|
+
Array_ extends UnknownArray,
|
|
65
|
+
Options extends SplitOnRestElementOptions = {},
|
|
66
|
+
> =
|
|
67
|
+
Array_ extends unknown // For distributing `Array_`
|
|
68
|
+
? IfNotAnyOrNever<Array_, _SplitOnRestElement<
|
|
69
|
+
Array_,
|
|
70
|
+
ApplyDefaultOptions<SplitOnRestElementOptions, DefaultSplitOnRestElementOptions, Options>
|
|
71
|
+
>> extends infer Result extends UnknownArray
|
|
72
|
+
? If<IsArrayReadonly<Array_>, Readonly<Result>, Result>
|
|
73
|
+
: never // Should never happen
|
|
74
|
+
: never; // Should never happen
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
Deconstructs an array on its rest element and returns the split portions.
|
|
78
|
+
*/
|
|
79
|
+
export type _SplitOnRestElement<
|
|
80
|
+
Array_ extends UnknownArray,
|
|
81
|
+
Options extends Required<SplitOnRestElementOptions>,
|
|
82
|
+
HeadAcc extends UnknownArray = [],
|
|
83
|
+
TailAcc extends UnknownArray = [],
|
|
84
|
+
> =
|
|
85
|
+
keyof Array_ & `${number}` extends never
|
|
86
|
+
// Enters this branch, if `Array_` is empty (e.g., []),
|
|
87
|
+
// or `Array_` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
|
|
88
|
+
? Array_ extends readonly [...infer Rest, infer Last]
|
|
89
|
+
? _SplitOnRestElement<Rest, Options, HeadAcc, [Last, ...TailAcc]> // Accumulate elements that are present after the rest element.
|
|
90
|
+
: [HeadAcc, Array_ extends readonly [] ? [] : Array_, TailAcc] // Add the rest element between the accumulated elements.
|
|
91
|
+
: Array_ extends readonly [(infer First)?, ...infer Rest]
|
|
92
|
+
? _SplitOnRestElement<
|
|
93
|
+
Rest, Options,
|
|
94
|
+
[
|
|
95
|
+
...HeadAcc,
|
|
96
|
+
...IsOptionalKeyOf<Array_, '0'> extends true
|
|
97
|
+
? Options['preserveOptionalModifier'] extends false
|
|
98
|
+
? [If<IsExactOptionalPropertyTypesEnabled, First, First | undefined>] // Add `| undefined` for optional elements, if `exactOptionalPropertyTypes` is disabled.
|
|
99
|
+
: [First?]
|
|
100
|
+
: [First],
|
|
101
|
+
],
|
|
102
|
+
TailAcc
|
|
103
|
+
> // Accumulate elements that are present before the rest element.
|
|
104
|
+
: never; // Should never happen, since `[(infer First)?, ...infer Rest]` is a top-type for arrays.
|
|
105
|
+
|
|
106
|
+
export {};
|
package/source/split.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ Split options.
|
|
|
8
8
|
|
|
9
9
|
@see {@link Split}
|
|
10
10
|
*/
|
|
11
|
-
type SplitOptions = {
|
|
11
|
+
export type SplitOptions = {
|
|
12
12
|
/**
|
|
13
13
|
When enabled, instantiations with non-literal string types (e.g., `string`, `Uppercase<string>`, `on${string}`) simply return back `string[]` without performing any splitting, as the exact structure cannot be statically determined.
|
|
14
14
|
|
|
@@ -86,3 +86,5 @@ type SplitHelper<
|
|
|
86
86
|
: string[]
|
|
87
87
|
: never // Should never happen
|
|
88
88
|
: never; // Should never happen
|
|
89
|
+
|
|
90
|
+
export {};
|
package/source/spread.d.ts
CHANGED
package/source/string-slice.d.ts
CHANGED
package/source/stringified.d.ts
CHANGED
package/source/subtract.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {NumberAbsolute,
|
|
1
|
+
import type {NumberAbsolute, 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
|
+
import type {TupleOf} from './tuple-of.d.ts';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
Returns the difference between two numbers.
|
|
@@ -60,7 +61,7 @@ type SubtractPostChecks<A extends number, B extends number, AreNegative = [IsNeg
|
|
|
60
61
|
// When both numbers are negative we subtract the absolute values and then reverse the sign
|
|
61
62
|
? ReverseSign<SubtractPositives<NumberAbsolute<A>, NumberAbsolute<B>>>
|
|
62
63
|
// When the signs are different we can add the absolute values and then reverse the sign if A < B
|
|
63
|
-
: [...
|
|
64
|
+
: [...TupleOf<NumberAbsolute<A>>, ...TupleOf<NumberAbsolute<B>>] extends infer R extends unknown[]
|
|
64
65
|
? LessThan<A, B> extends true ? ReverseSign<R['length']> : R['length']
|
|
65
66
|
: never;
|
|
66
67
|
|
|
@@ -78,6 +79,8 @@ Subtracts two positive numbers A and B such that A > B.
|
|
|
78
79
|
*/
|
|
79
80
|
type SubtractIfAGreaterThanB<A extends number, B extends number> =
|
|
80
81
|
// This is where we always want to end up and do the actual subtraction
|
|
81
|
-
|
|
82
|
+
TupleOf<A> extends [...TupleOf<B>, ...infer R]
|
|
82
83
|
? R['length']
|
|
83
84
|
: never;
|
|
85
|
+
|
|
86
|
+
export {};
|
package/source/sum.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {TupleOf} from './tuple-of.d.ts';
|
|
2
|
+
import type {NumberAbsolute, TupleMax, ReverseSign} from './internal/index.d.ts';
|
|
2
3
|
import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric.d.ts';
|
|
3
4
|
import type {Subtract} from './subtract.d.ts';
|
|
4
5
|
|
|
@@ -73,6 +74,8 @@ type SumPostChecks<A extends number, B extends number, AreNegative = [IsNegative
|
|
|
73
74
|
Adds two positive numbers.
|
|
74
75
|
*/
|
|
75
76
|
type SumPositives<A extends number, B extends number> =
|
|
76
|
-
[...
|
|
77
|
+
[...TupleOf<A>, ...TupleOf<B>]['length'] extends infer Result extends number
|
|
77
78
|
? Result
|
|
78
79
|
: never;
|
|
80
|
+
|
|
81
|
+
export {};
|
package/source/tagged-union.d.ts
CHANGED
package/source/tagged.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type tag from 'tagged-tag';
|
|
2
2
|
|
|
3
|
+
// eslint-disable-next-line type-fest/require-exported-types
|
|
3
4
|
export type TagContainer<Token> = {
|
|
4
5
|
readonly [tag]: Token;
|
|
5
6
|
};
|
|
@@ -256,3 +257,5 @@ export type UnwrapOpaque<OpaqueType extends TagContainer<unknown>> =
|
|
|
256
257
|
: OpaqueType;
|
|
257
258
|
|
|
258
259
|
export {type default as tag} from 'tagged-tag';
|
|
260
|
+
|
|
261
|
+
export {};
|