free-types-core 0.4.3 → 0.4.5
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/dist/Const.d.ts +1 -1
- package/dist/Remaining.d.ts +1 -1
- package/dist/Replace.d.ts +1 -1
- package/dist/Type.d.ts +6 -6
- package/dist/apply.d.ts +5 -5
- package/dist/free-types.d.ts +1 -1
- package/dist/helpers.d.ts +12 -12
- package/dist/hkt.d.ts +2 -2
- package/dist/inferArgs.d.ts +1 -1
- package/dist/partial.d.ts +5 -4
- package/dist/unwrap.d.ts +9 -9
- package/dist/utils.d.ts +21 -21
- package/package.json +1 -1
package/dist/Const.d.ts
CHANGED
package/dist/Remaining.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { Type } from './Type';
|
|
|
2
2
|
import { Slice, Subtract } from './utils';
|
|
3
3
|
export { Remaining };
|
|
4
4
|
/** Use as a type constraint to match a Type whose state of application is known */
|
|
5
|
-
type Remaining<T extends Type, R extends number> = unknown[] extends T['constraints'] ? Type : Type<Slice<T['constraints'], Subtract<T['constraints']['length'], R>, T['constraints']['length']>, T['type']>;
|
|
5
|
+
declare type Remaining<T extends Type, R extends number> = unknown[] extends T['constraints'] ? Type : Type<Slice<T['constraints'], Subtract<T['constraints']['length'], R>, T['constraints']['length']>, T['type']>;
|
package/dist/Replace.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export { Replace };
|
|
|
6
6
|
*
|
|
7
7
|
* Can be used to constrain the inner value of a type
|
|
8
8
|
*/
|
|
9
|
-
type Replace<T, Args extends U['type']['constraints'], From extends Search = TypesMap, U extends Unwrapped = unwrap<T, From>> = apply<U['type'], Args>;
|
|
9
|
+
declare type Replace<T, Args extends U['type']['constraints'], From extends Search = TypesMap, U extends Unwrapped = unwrap<T, From>> = apply<U['type'], Args>;
|
package/dist/Type.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Tuple } from './utils';
|
|
2
2
|
export { Type };
|
|
3
3
|
/** Extend `Type<Input?, Output?>` with an interface to produce a free type, or use it as a type constraint.*/
|
|
4
|
-
type Type<Input extends number | unknown[] = unknown[], Output = unknown> = CreateType<{
|
|
4
|
+
declare type Type<Input extends number | unknown[] = unknown[], Output = unknown> = CreateType<{
|
|
5
5
|
type: Output;
|
|
6
6
|
constraints: Constraints<Input, Slots<Input>>;
|
|
7
7
|
arguments: unknown[];
|
|
@@ -24,10 +24,10 @@ interface CreateType<T extends {
|
|
|
24
24
|
8: unknown;
|
|
25
25
|
9: unknown;
|
|
26
26
|
}
|
|
27
|
-
type Slots<T> = T extends Precomputable ? PrecomputedSlots[T & Precomputable] : Tuple<T extends unknown[] ? T['length'] : T extends number ? T : number>;
|
|
28
|
-
type Constraints<Input, Slots> = number extends Input ? unknown[] : unknown[] extends Input ? unknown[] : Input extends unknown[] ? Input : Slots;
|
|
29
|
-
type PrecomputedSlots = {
|
|
27
|
+
declare type Slots<T> = T extends Precomputable ? PrecomputedSlots[T & Precomputable] : Tuple<T extends unknown[] ? T['length'] : T extends number ? T : number>;
|
|
28
|
+
declare type Constraints<Input, Slots> = number extends Input ? unknown[] : unknown[] extends Input ? unknown[] : Input extends unknown[] ? Input : Slots;
|
|
29
|
+
declare type PrecomputedSlots = {
|
|
30
30
|
[I in Precomputable]: Tuple<Seq10[I]>;
|
|
31
31
|
};
|
|
32
|
-
type Precomputable = Seq10[number];
|
|
33
|
-
type Seq10 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
32
|
+
declare type Precomputable = Seq10[number];
|
|
33
|
+
declare type Seq10 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
package/dist/apply.d.ts
CHANGED
|
@@ -2,21 +2,21 @@ import { Type } from './Type';
|
|
|
2
2
|
import { ArrayKeys, Next } from './utils';
|
|
3
3
|
export { apply, $apply, Generic };
|
|
4
4
|
/** Apply a free type with all its arguments and evaluate the type */
|
|
5
|
-
type apply<$T extends Type, Args extends $T['constraints'] = []> = applyUnsafe<$T, Args>;
|
|
5
|
+
declare type apply<$T extends Type, Args extends $T['constraints'] = []> = applyUnsafe<$T, Args>;
|
|
6
6
|
interface $apply<Args extends unknown[] = []> extends Type<[Type]> {
|
|
7
7
|
type: apply<this[0] extends Type ? this[0] : Type, Args>;
|
|
8
8
|
}
|
|
9
9
|
/** Apply a free type `$T` with its type constraints. */
|
|
10
|
-
type Generic<$T extends Type> = _apply<$T, $T['constraints']>;
|
|
11
|
-
type applyUnsafe<$T extends {
|
|
10
|
+
declare type Generic<$T extends Type> = _apply<$T, $T['constraints']>;
|
|
11
|
+
declare type applyUnsafe<$T extends {
|
|
12
12
|
type: unknown;
|
|
13
13
|
constraints: {
|
|
14
14
|
length: number;
|
|
15
15
|
};
|
|
16
16
|
}, Args extends unknown[]> = number extends $T['constraints']['length'] ? _apply<$T, Args> : _apply<$T, Take<Args, Required<$T['constraints']>['length']>>;
|
|
17
|
-
type _apply<T extends {
|
|
17
|
+
declare type _apply<T extends {
|
|
18
18
|
type: unknown;
|
|
19
19
|
}, Args> = (T & Omit<Args, ArrayKeys> & {
|
|
20
20
|
arguments: Args;
|
|
21
21
|
})['type'];
|
|
22
|
-
type Take<T extends unknown[], To extends number, I extends number = 0, R extends unknown[] = []> = I extends To ? R : Take<T, To, Next<I>, [...R, T[I]]>;
|
|
22
|
+
declare type Take<T extends unknown[], To extends number, I extends number = 0, R extends unknown[] = []> = I extends To ? R : Take<T, To, Next<I>, [...R, T[I]]>;
|
package/dist/free-types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { $Id as Id, $Record as Record, $Array as Array, $Tuple as Tuple, $Readon
|
|
|
4
4
|
interface $Id extends Type<1> {
|
|
5
5
|
type: this[0];
|
|
6
6
|
}
|
|
7
|
-
type Key = string | number | symbol;
|
|
7
|
+
declare type Key = string | number | symbol;
|
|
8
8
|
interface $Record extends Type<[Key, unknown]> {
|
|
9
9
|
type: Record<this[0] & Key, this[1]>;
|
|
10
10
|
}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
1
|
import { Next, IsUnknown, Prev } from './utils';
|
|
2
2
|
export { At, Checked, Lossy, Optional, A, B, C, D, E };
|
|
3
|
-
type Type<N extends number> = {
|
|
3
|
+
declare type Type<N extends number> = {
|
|
4
4
|
constraints: {
|
|
5
5
|
[K in Prev<N>]: unknown;
|
|
6
6
|
};
|
|
7
7
|
arguments: unknown[];
|
|
8
8
|
};
|
|
9
|
-
type Type_<N extends number> = {
|
|
9
|
+
declare type Type_<N extends number> = {
|
|
10
10
|
constraints: {
|
|
11
11
|
[K in Prev<N>]?: unknown;
|
|
12
12
|
};
|
|
13
13
|
arguments: unknown[];
|
|
14
14
|
};
|
|
15
|
-
type Default = {
|
|
15
|
+
declare type Default = {
|
|
16
16
|
constraints: [0, 1, 2, 3, 4];
|
|
17
17
|
arguments: unknown[];
|
|
18
18
|
};
|
|
19
19
|
/** - safely index `this`
|
|
20
20
|
* - optionally take a fallback
|
|
21
21
|
*/
|
|
22
|
-
type At<N extends number, This extends Type<Next<N>>, Fallback = unknown> = IsUnknown<This['arguments'][N]> extends true ? Fallback : This['arguments'][N];
|
|
22
|
+
declare type At<N extends number, This extends Type<Next<N>>, Fallback = unknown> = IsUnknown<This['arguments'][N]> extends true ? Fallback : This['arguments'][N];
|
|
23
23
|
/** - safely index `this`
|
|
24
24
|
* - defuse the corresponding type constraint with an inline conditional
|
|
25
25
|
* - optionally take a fallback
|
|
26
26
|
*/
|
|
27
|
-
type Checked<N extends number, This extends Type<Next<N>>, Fallback = N extends keyof This['constraints'] ? This['constraints'][N] : never> = N extends keyof This['constraints'] ? This['arguments'][N] extends This['constraints'][N] ? This['arguments'][N] : Fallback : never;
|
|
27
|
+
declare type Checked<N extends number, This extends Type<Next<N>>, Fallback = N extends keyof This['constraints'] ? This['constraints'][N] : never> = N extends keyof This['constraints'] ? This['arguments'][N] extends This['constraints'][N] ? This['arguments'][N] : Fallback : never;
|
|
28
28
|
/** - safely index `this`
|
|
29
29
|
* - works on optional parameters
|
|
30
30
|
* - defuse the corresponding type constraint with an inline conditional
|
|
31
31
|
* - optionally take a fallback
|
|
32
32
|
*/
|
|
33
|
-
type Optional<N extends number, This extends Type_<Next<N>>, Fallback = N extends keyof This['constraints'] ? Exclude<This['constraints'][N], undefined> : never> = N extends keyof This['constraints'] ? This['arguments'][N] extends Exclude<This['constraints'][N], undefined> ? This['arguments'][N] : Fallback : never;
|
|
33
|
+
declare type Optional<N extends number, This extends Type_<Next<N>>, Fallback = N extends keyof This['constraints'] ? Exclude<This['constraints'][N], undefined> : never> = N extends keyof This['constraints'] ? This['arguments'][N] extends Exclude<This['constraints'][N], undefined> ? This['arguments'][N] : Fallback : never;
|
|
34
34
|
/** - safely index `this`
|
|
35
35
|
* - intersect the corresponding type constraint
|
|
36
36
|
*/
|
|
37
|
-
type Lossy<N extends number, This extends Type<Next<N>>> = N extends keyof This['constraints'] ? This['arguments'][N] & This['constraints'][N] : never;
|
|
37
|
+
declare type Lossy<N extends number, This extends Type<Next<N>>> = N extends keyof This['constraints'] ? This['arguments'][N] & This['constraints'][N] : never;
|
|
38
38
|
/** - safely index `this`
|
|
39
39
|
* - intersect the corresponding type constraint
|
|
40
40
|
* - equals `0` When no argument is supplied
|
|
41
41
|
*/
|
|
42
|
-
type A<This extends Type<1> = Default> = This['arguments'][0] & This['constraints'][0];
|
|
42
|
+
declare type A<This extends Type<1> = Default> = This['arguments'][0] & This['constraints'][0];
|
|
43
43
|
/** - safely index `this`
|
|
44
44
|
* - intersect the corresponding type constraint
|
|
45
45
|
* - equals `1` When no argument is supplied
|
|
46
46
|
*/
|
|
47
|
-
type B<This extends Type<2> = Default> = This['arguments'][1] & This['constraints'][1];
|
|
47
|
+
declare type B<This extends Type<2> = Default> = This['arguments'][1] & This['constraints'][1];
|
|
48
48
|
/** - safely index `this`
|
|
49
49
|
* - intersect the corresponding type constraint
|
|
50
50
|
* - equals `2` When no argument is supplied
|
|
51
51
|
*/
|
|
52
|
-
type C<This extends Type<3> = Default> = This['arguments'][2] & This['constraints'][2];
|
|
52
|
+
declare type C<This extends Type<3> = Default> = This['arguments'][2] & This['constraints'][2];
|
|
53
53
|
/** - safely index `this`
|
|
54
54
|
* - intersect the corresponding type constraint
|
|
55
55
|
* - equals `3` When no argument is supplied
|
|
56
56
|
*/
|
|
57
|
-
type D<This extends Type<4> = Default> = This['arguments'][3] & This['constraints'][3];
|
|
57
|
+
declare type D<This extends Type<4> = Default> = This['arguments'][3] & This['constraints'][3];
|
|
58
58
|
/** - safely index `this`
|
|
59
59
|
* - intersect the corresponding type constraint
|
|
60
60
|
* - equals `4` When no argument is supplied
|
|
61
61
|
*/
|
|
62
|
-
type E<This extends Type<5> = Default> = This['arguments'][4] & This['constraints'][4];
|
|
62
|
+
declare type E<This extends Type<5> = Default> = This['arguments'][4] & This['constraints'][4];
|
package/dist/hkt.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Type } from "./Type";
|
|
2
2
|
export { HKT, Contra };
|
|
3
3
|
/** Interfaces extending this type are able to use `hkt` internally. */
|
|
4
|
-
type HKT = {
|
|
4
|
+
declare type HKT = {
|
|
5
5
|
HKT: [any, ...any[]];
|
|
6
6
|
};
|
|
7
7
|
/** Expect a free type with contravariant arguments */
|
|
8
|
-
type Contra<$T extends Type, $U extends Type> = $U['constraints'] extends $T['constraints'] ? $T['type'] extends $U['type'] ? Type : Type<$T['constraints'], $U['type']> : {
|
|
8
|
+
declare type Contra<$T extends Type, $U extends Type> = $U['constraints'] extends $T['constraints'] ? $T['type'] extends $U['type'] ? Type : Type<$T['constraints'], $U['type']> : {
|
|
9
9
|
'Contravariance issue': {
|
|
10
10
|
'the input': $U['constraints'];
|
|
11
11
|
'is not assignable to': $T['constraints'];
|
package/dist/inferArgs.d.ts
CHANGED
package/dist/partial.d.ts
CHANGED
|
@@ -2,16 +2,17 @@ import { Type } from './Type';
|
|
|
2
2
|
import { apply } from './apply';
|
|
3
3
|
import { Slice, Subtract, ToTuple } from './utils';
|
|
4
4
|
export { partial, partialRight, PartialRight, $partial };
|
|
5
|
+
export { PartialType };
|
|
5
6
|
/** Return a new type based upon `$T`, with `Args` already applied, expecting the remaining arguments */
|
|
6
|
-
type partial<$T extends Type, Args extends Partial<$Model['constraints']>, $Model extends Type = $T> = $T extends $Model ? Args extends unknown[] ? _partial<$T, Args> : never : never;
|
|
7
|
+
declare type partial<$T extends Type, Args extends Partial<$Model['constraints']>, $Model extends Type = $T> = $T extends $Model ? Args extends unknown[] ? _partial<$T, Args> : never : never;
|
|
7
8
|
/** A free version of `partial` */
|
|
8
9
|
interface $partial<$T extends Type> extends Type<1> {
|
|
9
10
|
type: _partial<$T, [this['arguments'][0]]>;
|
|
10
11
|
}
|
|
11
|
-
type _partial<$T extends Type, Args extends unknown[]> = PartialType<$T, Args, Slice<$T['constraints'], Args['length'], Required<$T['constraints']>['length']>, 'left'>;
|
|
12
|
+
declare type _partial<$T extends Type, Args extends unknown[]> = PartialType<$T, Args, Slice<$T['constraints'], Args['length'], Required<$T['constraints']>['length']>, 'left'>;
|
|
12
13
|
/** Return a new type based upon `$T`, with `Args` already applied to the rightmost parameters of `$T`, and expecting the remaining arguments */
|
|
13
|
-
type partialRight<$T extends Type, Args extends PartialRight<$Model['constraints']>, $Model extends Type = $T> = $T extends $Model ? PartialType<$T, Args, Slice<$T['constraints'], 0, Subtract<Required<$T['constraints']>['length'], Args['length']>>, 'right'> : never;
|
|
14
|
-
type PartialRight<T extends unknown[], R = never> = T extends [unknown, ...(infer Rest)] ? PartialRight<Rest, T | R> : [] | R;
|
|
14
|
+
declare type partialRight<$T extends Type, Args extends PartialRight<$Model['constraints']>, $Model extends Type = $T> = $T extends $Model ? PartialType<$T, Args, Slice<$T['constraints'], 0, Subtract<Required<$T['constraints']>['length'], Args['length']>>, 'right'> : never;
|
|
15
|
+
declare type PartialRight<T extends unknown[], R = never> = T extends [unknown, ...(infer Rest)] ? PartialRight<Rest, T | R> : [] | R;
|
|
15
16
|
interface PartialType<$T extends Type, Applied extends unknown[], Constraints extends unknown[], Direction> extends Type {
|
|
16
17
|
type: apply<$T, Direction extends 'left' ? [...Applied, ...ToTuple<this['arguments']>] : [...ToTuple<this['arguments']>, ...Applied]>;
|
|
17
18
|
constraints: Constraints;
|
package/dist/unwrap.d.ts
CHANGED
|
@@ -4,30 +4,30 @@ import { inferArgs } from './inferArgs';
|
|
|
4
4
|
import { Generic, apply } from './apply';
|
|
5
5
|
import { TypesMap } from './TypesMap';
|
|
6
6
|
import { Tuple, ReadonlyTuple, Array, ReadonlyArray } from './free-types';
|
|
7
|
-
type Search = Type | SearchList;
|
|
8
|
-
type SearchList = Type[] | Record<string, Type> | Interface;
|
|
9
|
-
type Interface = {
|
|
7
|
+
declare type Search = Type | SearchList;
|
|
8
|
+
declare type SearchList = Type[] | Record<string, Type> | Interface;
|
|
9
|
+
declare type Interface = {
|
|
10
10
|
[k: string]: any;
|
|
11
11
|
} & {
|
|
12
12
|
[Symbol.toStringTag]?: never;
|
|
13
13
|
};
|
|
14
14
|
export { unwrap, Unwrapped, Search };
|
|
15
15
|
/** Decompose a type into its constituents */
|
|
16
|
-
type unwrap<T, From extends Search = TypesMap> = T extends readonly unknown[] ? unwrapLists<T> : _unwrap<T, From extends Type ? [From] : From>;
|
|
17
|
-
type unwrapLists<T> = T extends unknown[] ? T extends [unknown, ...unknown[]] ? Unwrapped<'Tuple', Tuple, T> : Unwrapped<'Array', Array, [T[0]]> : T extends readonly [unknown, ...unknown[]] ? Unwrapped<'ReadonlyTuple', ReadonlyTuple, Mutable<T>> : Unwrapped<'ReadonlyArray', ReadonlyArray, [(T & unknown[])[0]]>;
|
|
18
|
-
type Mutable<T> = {
|
|
16
|
+
declare type unwrap<T, From extends Search = TypesMap> = T extends readonly unknown[] ? unwrapLists<T> : _unwrap<T, From extends Type ? [From] : From>;
|
|
17
|
+
declare type unwrapLists<T> = T extends unknown[] ? T extends [unknown, ...unknown[]] ? Unwrapped<'Tuple', Tuple, T> : Unwrapped<'Array', Array, [T[0]]> : T extends readonly [unknown, ...unknown[]] ? Unwrapped<'ReadonlyTuple', ReadonlyTuple, Mutable<T>> : Unwrapped<'ReadonlyArray', ReadonlyArray, [(T & unknown[])[0]]>;
|
|
18
|
+
declare type Mutable<T> = {
|
|
19
19
|
-readonly [K in keyof T]: K extends ArrayKeys ? T[K] : T[K];
|
|
20
20
|
};
|
|
21
|
-
type _unwrap<T, From extends SearchList, R = {
|
|
21
|
+
declare type _unwrap<T, From extends SearchList, R = {
|
|
22
22
|
[K in keyof From as K extends ArrayKeys ? never : K extends string ? K : never]: From[K] extends Type ? Branch<T, From[K], K>[T extends Generic<From[K]> ? 'match' : 'miss'] : never;
|
|
23
23
|
}> = R[keyof R];
|
|
24
24
|
interface Branch<T, $T extends Type, K> {
|
|
25
25
|
match: Disambiguate<T, $T, inferArgs<T, $T>, K & string>;
|
|
26
26
|
miss: never;
|
|
27
27
|
}
|
|
28
|
-
type Disambiguate<T, $T extends Type, Args extends unknown[], K extends string> = Eq<T, apply<$T, Args>> extends true ? Unwrapped<K, $T, Args> : never;
|
|
28
|
+
declare type Disambiguate<T, $T extends Type, Args extends unknown[], K extends string> = Eq<T, apply<$T, Args>> extends true ? Unwrapped<K, $T, Args> : never;
|
|
29
29
|
/** The result of unwrapping a type with `unwrap` */
|
|
30
|
-
type Unwrapped<URI extends string = string, T extends Type = Type, A = unknown[]> = {
|
|
30
|
+
declare type Unwrapped<URI extends string = string, T extends Type = Type, A = unknown[]> = {
|
|
31
31
|
URI: URI;
|
|
32
32
|
type: T;
|
|
33
33
|
args: A;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
export { Natural, Prev, Next, Subtract };
|
|
2
2
|
export { ArrayKeys, Slice, ToTuple, Tuple, Head, Tail, Last, Init };
|
|
3
3
|
export { Extends, Eq, IsUnknown, IsAny, IsOptional };
|
|
4
|
-
type Natural = [0, ..._Next];
|
|
5
|
-
type Prev<I extends number> = number extends I ? number : number & _Prev[I];
|
|
6
|
-
type _Prev = [never, ...Natural];
|
|
7
|
-
type Next<I extends number> = number extends I ? number : number & _Next[I];
|
|
8
|
-
type _Next = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64];
|
|
9
|
-
type Subtract<A extends number, B extends number> = number extends A ? number : number extends B ? number : _Subtract<A, B>;
|
|
10
|
-
type _Subtract<A extends number, B extends number, _A = Prev<A>, _B = Prev<B>> = B extends 0 ? A : [_A] extends [never] ? never : [_B] extends never ? never : _Subtract<_A & number, _B & number>;
|
|
11
|
-
type ArrayKeys = Exclude<keyof [], never>;
|
|
12
|
-
type Slice<T extends unknown[], From extends number, To extends number = Required<T>['length'], I extends number = From, R extends unknown[] = []> = I extends To ? R : Slice<T, From, To, Next<I>, IsOptional<T, I> extends true ? [...R, T[I]?] : [...R, T[I]]>;
|
|
13
|
-
type IsOptional<T extends unknown[], I extends number> = [
|
|
4
|
+
declare type Natural = [0, ..._Next];
|
|
5
|
+
declare type Prev<I extends number> = number extends I ? number : number & _Prev[I];
|
|
6
|
+
declare type _Prev = [never, ...Natural];
|
|
7
|
+
declare type Next<I extends number> = number extends I ? number : number & _Next[I];
|
|
8
|
+
declare type _Next = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64];
|
|
9
|
+
declare type Subtract<A extends number, B extends number> = number extends A ? number : number extends B ? number : _Subtract<A, B>;
|
|
10
|
+
declare type _Subtract<A extends number, B extends number, _A = Prev<A>, _B = Prev<B>> = B extends 0 ? A : [_A] extends [never] ? never : [_B] extends never ? never : _Subtract<_A & number, _B & number>;
|
|
11
|
+
declare type ArrayKeys = Exclude<keyof [], never>;
|
|
12
|
+
declare type Slice<T extends unknown[], From extends number, To extends number = Required<T>['length'], I extends number = From, R extends unknown[] = []> = I extends To ? R : Slice<T, From, To, Next<I>, IsOptional<T, I> extends true ? [...R, T[I]?] : [...R, T[I]]>;
|
|
13
|
+
declare type IsOptional<T extends unknown[], I extends number> = [
|
|
14
14
|
{
|
|
15
15
|
[K in T['length'] as K]: K extends I ? never : unknown;
|
|
16
16
|
}[I]
|
|
17
17
|
] extends [never] ? true : false;
|
|
18
|
-
type ToTuple<T extends readonly unknown[], I extends number = 0, R extends unknown[] = []> = any[] extends T ? T[0][] : I extends T['length'] ? R : ToTuple<T, Next<I>, [...R, T[I]]>;
|
|
19
|
-
type Tuple<L extends number, T = unknown, R extends unknown[] = []> = number extends L ? T[] : L extends R['length'] ? R : Tuple<L, T, [T, ...R]>;
|
|
20
|
-
type Head<T extends [unknown, ...unknown[]]> = T[0];
|
|
21
|
-
type Tail<T extends [unknown, ...unknown[]]> = T extends [unknown, ...infer R] ? R : never;
|
|
22
|
-
type Last<T extends unknown[]> = T[Prev<T['length']>];
|
|
23
|
-
type Init<T extends [unknown, ...unknown[]]> = T extends [...infer R, unknown] ? R : never;
|
|
24
|
-
type IsUnknown<T> = unknown extends T ? IsAny<T> extends false ? true : false : false;
|
|
25
|
-
type IsAny<T> = Extends<T | anything, T & anything>;
|
|
26
|
-
type Extends<A, B> = [A] extends [B] ? true : false;
|
|
27
|
-
type Eq<A, B> = [A] extends [B] ? [B] extends [A] ? true : false : false;
|
|
18
|
+
declare type ToTuple<T extends readonly unknown[], I extends number = 0, R extends unknown[] = []> = any[] extends T ? T[0][] : I extends T['length'] ? R : ToTuple<T, Next<I>, [...R, T[I]]>;
|
|
19
|
+
declare type Tuple<L extends number, T = unknown, R extends unknown[] = []> = number extends L ? T[] : L extends R['length'] ? R : Tuple<L, T, [T, ...R]>;
|
|
20
|
+
declare type Head<T extends [unknown, ...unknown[]]> = T[0];
|
|
21
|
+
declare type Tail<T extends [unknown, ...unknown[]]> = T extends [unknown, ...infer R] ? R : never;
|
|
22
|
+
declare type Last<T extends unknown[]> = T[Prev<T['length']>];
|
|
23
|
+
declare type Init<T extends [unknown, ...unknown[]]> = T extends [...infer R, unknown] ? R : never;
|
|
24
|
+
declare type IsUnknown<T> = unknown extends T ? IsAny<T> extends false ? true : false : false;
|
|
25
|
+
declare type IsAny<T> = Extends<T | anything, T & anything>;
|
|
26
|
+
declare type Extends<A, B> = [A] extends [B] ? true : false;
|
|
27
|
+
declare type Eq<A, B> = [A] extends [B] ? [B] extends [A] ? true : false : false;
|
|
28
28
|
declare const thing: unique symbol;
|
|
29
|
-
type anything = typeof thing;
|
|
29
|
+
declare type anything = typeof thing;
|
package/package.json
CHANGED