free-types-core 0.8.2 → 0.8.4

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 CHANGED
@@ -1,28 +1,28 @@
1
- import { Type } from './Type';
2
- export { Const, $Const };
3
- /**
4
- * Turn a type `T` into a constant `Type<❋, T>`, totally ignoring arity and type constraints on its input.
5
- */
6
- declare type Const<T> = {
7
- type: T;
8
- constraints: any;
9
- arguments: any[] & {
10
- length: any;
11
- };
12
- 0: any;
13
- 1: any;
14
- 2: any;
15
- 3: any;
16
- 4: any;
17
- 5: any;
18
- 6: any;
19
- 7: any;
20
- 8: any;
21
- 9: any;
22
- };
23
- /**
24
- * Turn the input into a constant `Type<❋, T>`, totally ignoring arity and type constraints on its input.
25
- */
26
- interface $Const extends Type<1> {
27
- type: Const<this[0]>;
28
- }
1
+ import { Type } from './Type';
2
+ export { Const, $Const };
3
+ /**
4
+ * Turn a type `T` into a constant `Type<❋, T>`, totally ignoring arity and type constraints on its input.
5
+ */
6
+ declare type Const<T> = {
7
+ type: T;
8
+ constraints: any;
9
+ arguments: any[] & {
10
+ length: any;
11
+ };
12
+ 0: any;
13
+ 1: any;
14
+ 2: any;
15
+ 3: any;
16
+ 4: any;
17
+ 5: any;
18
+ 6: any;
19
+ 7: any;
20
+ 8: any;
21
+ 9: any;
22
+ };
23
+ /**
24
+ * Turn the input into a constant `Type<❋, T>`, totally ignoring arity and type constraints on its input.
25
+ */
26
+ interface $Const extends Type<1> {
27
+ type: Const<this[0]>;
28
+ }
package/dist/Const.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,5 +1,5 @@
1
- import { Type } from './Type';
2
- import { Slice, Subtract } from './utils';
3
- export { Remaining };
4
- /** Use as a type constraint to match a Type whose state of application is known */
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']>;
1
+ import { Type } from './Type';
2
+ import { Slice, Subtract } from './utils';
3
+ export { Remaining };
4
+ /** Use as a type constraint to match a Type whose state of application is known */
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/Remaining.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/dist/Replace.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { unwrap, Unwrapped, Search } from './unwrap';
2
- import { apply } from './apply';
3
- import { TypesMap } from './TypesMap';
4
- export { Replace };
5
- /** Replace the inner value of a type with compatible arguments.
6
- *
7
- * Can be used to constrain the inner value of a type
8
- */
9
- declare type Replace<T, Args extends U['type']['constraints'], From extends Search = TypesMap, U extends Unwrapped = unwrap<T, From>> = apply<U['type'], Args>;
1
+ import { unwrap, Unwrapped, Search } from './unwrap';
2
+ import { apply } from './apply';
3
+ import { TypesMap } from './TypesMap';
4
+ export { Replace };
5
+ /** Replace the inner value of a type with compatible arguments.
6
+ *
7
+ * Can be used to constrain the inner value of a type
8
+ */
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/Replace.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/dist/Type.d.ts CHANGED
@@ -1,24 +1,24 @@
1
- import { Tuple } from './utils';
2
- export { Type };
3
- /** Extend `Type<Input?, Output?>` with an interface to produce a free type, or use it as a type constraint.*/
4
- declare type Type<Input extends number | unknown[] = unknown[], Output = unknown> = CreateType<{
5
- type: Output;
6
- constraints: Constraints<Input, Slots<Input>>;
7
- arguments: unknown[];
8
- }>;
9
- interface CreateType<T extends {
10
- type: unknown;
11
- constraints: unknown[];
12
- }> {
13
- [k: number]: unknown;
14
- type: T['type'];
15
- constraints: T['constraints'];
16
- arguments: unknown[];
17
- }
18
- declare type Slots<T> = T extends Precomputable ? PrecomputedSlots[T & Precomputable] : Tuple<T extends unknown[] ? T['length'] : T extends number ? T : number>;
19
- declare type Constraints<Input, Slots> = number extends Input ? unknown[] : unknown[] extends Input ? unknown[] : Input extends unknown[] ? Input : Slots;
20
- declare type PrecomputedSlots = {
21
- [I in Precomputable]: Tuple<Seq10[I]>;
22
- };
23
- declare type Precomputable = Seq10[number];
24
- declare type Seq10 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
1
+ import { Tuple } from './utils';
2
+ export { Type };
3
+ /** Extend `Type<Input?, Output?>` with an interface to produce a free type, or use it as a type constraint.*/
4
+ declare type Type<Input extends number | unknown[] = unknown[], Output = unknown> = CreateType<{
5
+ type: Output;
6
+ constraints: Constraints<Input, Slots<Input>>;
7
+ arguments: unknown[];
8
+ }>;
9
+ interface CreateType<T extends {
10
+ type: unknown;
11
+ constraints: unknown[];
12
+ }> {
13
+ [k: number]: unknown;
14
+ type: T['type'];
15
+ constraints: T['constraints'];
16
+ arguments: unknown[];
17
+ }
18
+ declare type Slots<T> = T extends Precomputable ? PrecomputedSlots[T & Precomputable] : Tuple<T extends unknown[] ? T['length'] : T extends number ? T : number>;
19
+ declare type Constraints<Input, Slots> = number extends Input ? unknown[] : unknown[] extends Input ? unknown[] : Input extends unknown[] ? Input : Slots;
20
+ declare type PrecomputedSlots = {
21
+ [I in Precomputable]: Tuple<Seq10[I]>;
22
+ };
23
+ declare type Precomputable = Seq10[number];
24
+ declare type Seq10 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
package/dist/Type.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,17 +1,17 @@
1
- import * as free from './free-types';
2
- /** A mapping of everyday free types which you can extend with module augmentation. */
3
- export interface TypesMap {
4
- Record: free.Record;
5
- Array: free.Array;
6
- Tuple: free.Tuple;
7
- ReadonlyTuple: free.ReadonlyTuple;
8
- ReadonlyArray: free.ReadonlyArray;
9
- Set: free.Set;
10
- ReadonlySet: free.ReadonlySet;
11
- WeakSet: free.WeakSet;
12
- Map: free.Map;
13
- ReadonlyMap: free.ReadonlyMap;
14
- WeakMap: free.WeakMap;
15
- Function: free.Function;
16
- Promise: free.Promise;
17
- }
1
+ import * as free from './free-types';
2
+ /** A mapping of everyday free types which you can extend with module augmentation. */
3
+ export interface TypesMap {
4
+ Record: free.Record;
5
+ Array: free.Array;
6
+ Tuple: free.Tuple;
7
+ ReadonlyTuple: free.ReadonlyTuple;
8
+ ReadonlyArray: free.ReadonlyArray;
9
+ Set: free.Set;
10
+ ReadonlySet: free.ReadonlySet;
11
+ WeakSet: free.WeakSet;
12
+ Map: free.Map;
13
+ ReadonlyMap: free.ReadonlyMap;
14
+ WeakMap: free.WeakMap;
15
+ Function: free.Function;
16
+ Promise: free.Promise;
17
+ }
package/dist/TypesMap.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/dist/apply.d.ts CHANGED
@@ -1,22 +1,22 @@
1
- import { Type } from './Type';
2
- import { ArrayKeys, Next } from './utils';
3
- export { apply, $apply, Generic };
4
- /** Apply a free type with all its arguments and evaluate the type */
5
- declare type apply<$T extends Type, Args extends $T['constraints'] = []> = applyUnsafe<$T, Args>;
6
- interface $apply<Args extends unknown[] = []> extends Type<[Type]> {
7
- type: apply<this[0] extends Type ? this[0] : Type, Args>;
8
- }
9
- /** Apply a free type `$T` with its type constraints. */
10
- declare type Generic<$T extends Type> = _apply<$T, $T['constraints']>;
11
- declare type applyUnsafe<$T extends {
12
- type: unknown;
13
- constraints: {
14
- length: number;
15
- };
16
- }, Args extends unknown[]> = number extends $T['constraints']['length'] ? _apply<$T, Args> : _apply<$T, Take<Args, Required<$T['constraints']>['length']>>;
17
- declare type _apply<T extends {
18
- type: unknown;
19
- }, Args> = (T & Omit<Args, ArrayKeys> & {
20
- arguments: Args;
21
- })['type'];
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]]>;
1
+ import { Type } from './Type';
2
+ import { ArrayKeys, Next } from './utils';
3
+ export { apply, $apply, Generic };
4
+ /** Apply a free type with all its arguments and evaluate the type */
5
+ declare type apply<$T extends Type, Args extends $T['constraints'] = []> = applyUnsafe<$T, Args>;
6
+ interface $apply<Args extends unknown[] = []> extends Type<[Type]> {
7
+ type: apply<this[0] extends Type ? this[0] : Type, Args>;
8
+ }
9
+ /** Apply a free type `$T` with its type constraints. */
10
+ declare type Generic<$T extends Type> = _apply<$T, $T['constraints']>;
11
+ declare type applyUnsafe<$T extends {
12
+ type: unknown;
13
+ constraints: {
14
+ length: number;
15
+ };
16
+ }, Args extends unknown[]> = number extends $T['constraints']['length'] ? _apply<$T, Args> : _apply<$T, Take<Args, Required<$T['constraints']>['length']>>;
17
+ declare type _apply<T extends {
18
+ type: unknown;
19
+ }, Args> = (T & Omit<Args, ArrayKeys> & {
20
+ arguments: Args;
21
+ })['type'];
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/apply.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,63 +1,63 @@
1
- import { Type } from './Type';
2
- import { ToTuple } from './utils';
3
- export { $Id as Id, $Record as Record, $Array as Array, $Tuple as Tuple, $ReadonlyTuple as ReadonlyTuple, $ReadonlyArray as ReadonlyArray, $Set as Set, $ReadonlySet as ReadonlySet, $WeakSet as WeakSet, $Map as Map, $ReadonlyMap as ReadonlyMap, $WeakMap as WeakMap, $Function as Function, $UnaryFunction as UnaryFunction, $Promise as Promise };
4
- interface $Id extends Type<1> {
5
- type: this[0];
6
- }
7
- declare type Key = string | number | symbol;
8
- interface $Record extends Type<[Key, unknown]> {
9
- type: Record<this[0] & Key, this[1]>;
10
- }
11
- interface $Array extends Type<1> {
12
- type: Array<this[0]>;
13
- }
14
- interface $Tuple extends Type {
15
- type: ToTuple<this['arguments']>;
16
- }
17
- interface $ReadonlyTuple extends Type {
18
- type: Readonly<ToTuple<this['arguments']>>;
19
- }
20
- interface $ReadonlyArray extends Type<1> {
21
- type: ReadonlyArray<this[0]>;
22
- }
23
- interface $Set extends Type<1> {
24
- type: Set<this[0]>;
25
- }
26
- interface $ReadonlySet extends Type<1> {
27
- type: ReadonlySet<this[0]>;
28
- }
29
- interface $WeakSet extends Type<[object]> {
30
- type: WeakSet<this[0] extends object ? this[0] : object>;
31
- }
32
- interface $Map extends Type<2> {
33
- type: Map<this[0], this[1]>;
34
- }
35
- interface $ReadonlyMap extends Type<2> {
36
- type: ReadonlyMap<this[0], this[1]>;
37
- }
38
- interface $WeakMap extends Type<[object, unknown]> {
39
- type: WeakMap<this[0] extends object ? this[0] : object, this[1]>;
40
- }
41
- interface $Function extends Type<[any[], unknown]> {
42
- type: (...args: this[0] extends any[] ? this[0] : any[]) => this[1];
43
- }
44
- interface $UnaryFunction extends Type<2> {
45
- type: (a: unknown extends this[0] ? any : this[0]) => this[1];
46
- }
47
- interface $Promise extends Type<1> {
48
- type: Promise<this[0]>;
49
- }
50
- declare global {
51
- interface Set<T> {
52
- }
53
- interface ReadonlySet<T> {
54
- }
55
- interface WeakSet<T> {
56
- }
57
- interface Map<K, V> {
58
- }
59
- interface ReadonlyMap<K, V> {
60
- }
61
- interface WeakMap<K, V> {
62
- }
63
- }
1
+ import { Type } from './Type';
2
+ import { ToTuple } from './utils';
3
+ export { $Id as Id, $Record as Record, $Array as Array, $Tuple as Tuple, $ReadonlyTuple as ReadonlyTuple, $ReadonlyArray as ReadonlyArray, $Set as Set, $ReadonlySet as ReadonlySet, $WeakSet as WeakSet, $Map as Map, $ReadonlyMap as ReadonlyMap, $WeakMap as WeakMap, $Function as Function, $UnaryFunction as UnaryFunction, $Promise as Promise };
4
+ interface $Id extends Type<1> {
5
+ type: this[0];
6
+ }
7
+ declare type Key = string | number | symbol;
8
+ interface $Record extends Type<[Key, unknown]> {
9
+ type: Record<this[0] & Key, this[1]>;
10
+ }
11
+ interface $Array extends Type<1> {
12
+ type: Array<this[0]>;
13
+ }
14
+ interface $Tuple extends Type {
15
+ type: ToTuple<this['arguments']>;
16
+ }
17
+ interface $ReadonlyTuple extends Type {
18
+ type: Readonly<ToTuple<this['arguments']>>;
19
+ }
20
+ interface $ReadonlyArray extends Type<1> {
21
+ type: ReadonlyArray<this[0]>;
22
+ }
23
+ interface $Set extends Type<1> {
24
+ type: Set<this[0]>;
25
+ }
26
+ interface $ReadonlySet extends Type<1> {
27
+ type: ReadonlySet<this[0]>;
28
+ }
29
+ interface $WeakSet extends Type<[object]> {
30
+ type: WeakSet<this[0] extends object ? this[0] : object>;
31
+ }
32
+ interface $Map extends Type<2> {
33
+ type: Map<this[0], this[1]>;
34
+ }
35
+ interface $ReadonlyMap extends Type<2> {
36
+ type: ReadonlyMap<this[0], this[1]>;
37
+ }
38
+ interface $WeakMap extends Type<[object, unknown]> {
39
+ type: WeakMap<this[0] extends object ? this[0] : object, this[1]>;
40
+ }
41
+ interface $Function extends Type<[any[], unknown]> {
42
+ type: (...args: this[0] extends any[] ? this[0] : any[]) => this[1];
43
+ }
44
+ interface $UnaryFunction extends Type<2> {
45
+ type: (a: unknown extends this[0] ? any : this[0]) => this[1];
46
+ }
47
+ interface $Promise extends Type<1> {
48
+ type: Promise<this[0]>;
49
+ }
50
+ declare global {
51
+ interface Set<T> {
52
+ }
53
+ interface ReadonlySet<T> {
54
+ }
55
+ interface WeakSet<T> {
56
+ }
57
+ interface Map<K, V> {
58
+ }
59
+ interface ReadonlyMap<K, V> {
60
+ }
61
+ interface WeakMap<K, V> {
62
+ }
63
+ }
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/dist/helpers.d.ts CHANGED
@@ -1,62 +1,62 @@
1
- import { Next, IsUnknown, Prev } from './utils';
2
- export { At, Checked, Lossy, Optional, A, B, C, D, E };
3
- declare type Type<N extends number> = {
4
- constraints: {
5
- [K in Prev<N>]: unknown;
6
- };
7
- arguments: unknown[];
8
- };
9
- declare type Type_<N extends number> = {
10
- constraints: {
11
- [K in Prev<N>]?: unknown;
12
- };
13
- arguments: unknown[];
14
- };
15
- declare type Default = {
16
- constraints: [0, 1, 2, 3, 4];
17
- arguments: unknown[];
18
- };
19
- /** - safely index `this`
20
- * - optionally take a fallback
21
- */
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
- /** - safely index `this`
24
- * - defuse the corresponding type constraint with an inline conditional
25
- * - optionally take a fallback
26
- */
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
- /** - safely index `this`
29
- * - works on optional parameters
30
- * - defuse the corresponding type constraint with an inline conditional
31
- * - optionally take a fallback
32
- */
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
- /** - safely index `this`
35
- * - intersect the corresponding type constraint
36
- */
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
- /** - safely index `this`
39
- * - intersect the corresponding type constraint
40
- * - equals `0` When no argument is supplied
41
- */
42
- declare type A<This extends Type<1> = Default> = This['arguments'][0] & This['constraints'][0];
43
- /** - safely index `this`
44
- * - intersect the corresponding type constraint
45
- * - equals `1` When no argument is supplied
46
- */
47
- declare type B<This extends Type<2> = Default> = This['arguments'][1] & This['constraints'][1];
48
- /** - safely index `this`
49
- * - intersect the corresponding type constraint
50
- * - equals `2` When no argument is supplied
51
- */
52
- declare type C<This extends Type<3> = Default> = This['arguments'][2] & This['constraints'][2];
53
- /** - safely index `this`
54
- * - intersect the corresponding type constraint
55
- * - equals `3` When no argument is supplied
56
- */
57
- declare type D<This extends Type<4> = Default> = This['arguments'][3] & This['constraints'][3];
58
- /** - safely index `this`
59
- * - intersect the corresponding type constraint
60
- * - equals `4` When no argument is supplied
61
- */
62
- declare type E<This extends Type<5> = Default> = This['arguments'][4] & This['constraints'][4];
1
+ import { Next, IsUnknown, Prev } from './utils';
2
+ export { At, Checked, Lossy, Optional, A, B, C, D, E };
3
+ declare type Type<N extends number> = {
4
+ constraints: {
5
+ [K in Prev<N>]: unknown;
6
+ };
7
+ arguments: unknown[];
8
+ };
9
+ declare type Type_<N extends number> = {
10
+ constraints: {
11
+ [K in Prev<N>]?: unknown;
12
+ };
13
+ arguments: unknown[];
14
+ };
15
+ declare type Default = {
16
+ constraints: [0, 1, 2, 3, 4];
17
+ arguments: unknown[];
18
+ };
19
+ /** - safely index `this`
20
+ * - optionally take a fallback
21
+ */
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
+ /** - safely index `this`
24
+ * - defuse the corresponding type constraint with an inline conditional
25
+ * - optionally take a fallback
26
+ */
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
+ /** - safely index `this`
29
+ * - works on optional parameters
30
+ * - defuse the corresponding type constraint with an inline conditional
31
+ * - optionally take a fallback
32
+ */
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
+ /** - safely index `this`
35
+ * - intersect the corresponding type constraint
36
+ */
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
+ /** - safely index `this`
39
+ * - intersect the corresponding type constraint
40
+ * - equals `0` When no argument is supplied
41
+ */
42
+ declare type A<This extends Type<1> = Default> = This['arguments'][0] & This['constraints'][0];
43
+ /** - safely index `this`
44
+ * - intersect the corresponding type constraint
45
+ * - equals `1` When no argument is supplied
46
+ */
47
+ declare type B<This extends Type<2> = Default> = This['arguments'][1] & This['constraints'][1];
48
+ /** - safely index `this`
49
+ * - intersect the corresponding type constraint
50
+ * - equals `2` When no argument is supplied
51
+ */
52
+ declare type C<This extends Type<3> = Default> = This['arguments'][2] & This['constraints'][2];
53
+ /** - safely index `this`
54
+ * - intersect the corresponding type constraint
55
+ * - equals `3` When no argument is supplied
56
+ */
57
+ declare type D<This extends Type<4> = Default> = This['arguments'][3] & This['constraints'][3];
58
+ /** - safely index `this`
59
+ * - intersect the corresponding type constraint
60
+ * - equals `4` When no argument is supplied
61
+ */
62
+ declare type E<This extends Type<5> = Default> = This['arguments'][4] & This['constraints'][4];
package/dist/helpers.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/dist/hkt.d.ts CHANGED
@@ -1,19 +1,19 @@
1
- import { Type } from "./Type";
2
- export { HKT, Contra };
3
- /** Interfaces extending this type are able to use `hkt` internally. */
4
- declare type HKT = {
5
- HKT: [any, ...any[]];
6
- };
7
- /** Expect a free type with contravariant arguments */
8
- declare type Contra<$T, $U extends Type> = Type & _Contra<$T, $U>['type'];
9
- interface _Contra<$T, $U extends Type> {
10
- type: $U['constraints'] extends this['$T']['constraints'] ? this['$T']['type'] extends $U['type'] ? Type : Type<this['$T']['constraints'], $U['type']> : {
11
- [K in 'Contravariance issue']: [
12
- 'the input',
13
- $U['constraints'],
14
- 'is not assignable to',
15
- this['$T']['constraints']
16
- ];
17
- };
18
- $T: $T extends Type ? $T : never;
19
- }
1
+ import { Type } from "./Type";
2
+ export { HKT, Contra };
3
+ /** Interfaces extending this type are able to use `hkt` internally. */
4
+ declare type HKT = {
5
+ HKT: [any, ...any[]];
6
+ };
7
+ /** Expect a free type with contravariant arguments */
8
+ declare type Contra<$T, $U extends Type> = Type & _Contra<$T, $U>['type'];
9
+ interface _Contra<$T, $U extends Type> {
10
+ type: $U['constraints'] extends this['$T']['constraints'] ? this['$T']['type'] extends $U['type'] ? Type : Type<this['$T']['constraints'], $U['type']> : {
11
+ [K in 'Contravariance issue']: [
12
+ 'the input',
13
+ $U['constraints'],
14
+ 'is not assignable to',
15
+ this['$T']['constraints']
16
+ ];
17
+ };
18
+ $T: $T extends Type ? $T : never;
19
+ }
package/dist/hkt.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- export * from './apply';
2
- export * from './partial';
3
- export * from './Remaining';
4
- export * from './Type';
5
- export * from './Const';
6
- export * from './helpers';
7
- export * from './inferArgs';
8
- export * from './unwrap';
9
- export * from './Replace';
10
- export * from './hkt';
11
- export * as free from './free-types';
12
- export { Slice, ToTuple, Head, Tail, Last, Init, IsUnknown, IsOptional, Next, Prev } from './utils';
13
- export { TypesMap } from './TypesMap';
1
+ export * from './apply';
2
+ export * from './partial';
3
+ export * from './Remaining';
4
+ export * from './Type';
5
+ export * from './Const';
6
+ export * from './helpers';
7
+ export * from './inferArgs';
8
+ export * from './unwrap';
9
+ export * from './Replace';
10
+ export * from './hkt';
11
+ export * as free from './free-types';
12
+ export { Slice, ToTuple, Head, Tail, Last, Init, IsUnknown, IsOptional, Next, Prev } from './utils';
13
+ export { TypesMap } from './TypesMap';
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- export * from './apply';
2
- export * from './partial';
3
- export * from './Remaining';
4
- export * from './Type';
5
- export * from './Const';
6
- export * from './helpers';
7
- export * from './inferArgs';
8
- export * from './unwrap';
9
- export * from './Replace';
10
- export * from './hkt';
11
- export * as free from './free-types';
1
+ export * from './apply';
2
+ export * from './partial';
3
+ export * from './Remaining';
4
+ export * from './Type';
5
+ export * from './Const';
6
+ export * from './helpers';
7
+ export * from './inferArgs';
8
+ export * from './unwrap';
9
+ export * from './Replace';
10
+ export * from './hkt';
11
+ export * as free from './free-types';
@@ -1,29 +1,29 @@
1
- import { Type } from './Type';
2
- import { apply } from './apply';
3
- export { inferArgs };
4
- declare type inferArgs<T, $T extends Type> = T extends apply<$T, [
5
- infer A,
6
- infer B,
7
- infer C,
8
- infer D,
9
- infer E,
10
- infer F,
11
- infer G,
12
- infer H,
13
- infer I,
14
- infer J
15
- ]> ? Extract<[A, B, C, D, E, F, G, H, I, J]>[$T['constraints']['length']] : never;
16
- interface Extract<T extends unknown[]> {
17
- [k: number]: unknown[];
18
- 0: [];
19
- 1: [T[0]];
20
- 2: [T[0], T[1]];
21
- 3: [T[0], T[1], T[2]];
22
- 4: [T[0], T[1], T[2], T[3]];
23
- 5: [T[0], T[1], T[2], T[3], T[4]];
24
- 6: [T[0], T[1], T[2], T[3], T[4], T[5]];
25
- 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6]];
26
- 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7]];
27
- 9: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8]];
28
- 10: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]];
29
- }
1
+ import { Type } from './Type';
2
+ import { apply } from './apply';
3
+ export { inferArgs };
4
+ declare type inferArgs<T, $T extends Type> = T extends apply<$T, [
5
+ infer A,
6
+ infer B,
7
+ infer C,
8
+ infer D,
9
+ infer E,
10
+ infer F,
11
+ infer G,
12
+ infer H,
13
+ infer I,
14
+ infer J
15
+ ]> ? Extract<[A, B, C, D, E, F, G, H, I, J]>[$T['constraints']['length']] : never;
16
+ interface Extract<T extends unknown[]> {
17
+ [k: number]: unknown[];
18
+ 0: [];
19
+ 1: [T[0]];
20
+ 2: [T[0], T[1]];
21
+ 3: [T[0], T[1], T[2]];
22
+ 4: [T[0], T[1], T[2], T[3]];
23
+ 5: [T[0], T[1], T[2], T[3], T[4]];
24
+ 6: [T[0], T[1], T[2], T[3], T[4], T[5]];
25
+ 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6]];
26
+ 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7]];
27
+ 9: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8]];
28
+ 10: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]];
29
+ }
package/dist/inferArgs.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/dist/partial.d.ts CHANGED
@@ -1,20 +1,20 @@
1
- import { Type } from './Type';
2
- import { apply } from './apply';
3
- import { Slice, Subtract, ToTuple } from './utils';
4
- export { partial, partialRight, PartialRight, $partial };
5
- export { PartialType };
6
- /** Return a new type based upon `$T`, with `Args` already applied, expecting the remaining arguments */
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;
8
- /** A free version of `partial` */
9
- interface $partial<$T extends Type> extends Type<1> {
10
- type: _partial<$T, [this['arguments'][0]]>;
11
- }
12
- declare type _partial<$T extends Type, Args extends unknown[]> = PartialType<$T, Args, Slice<$T['constraints'], Args['length'], Required<$T['constraints']>['length']>, 'left'>;
13
- /** Return a new type based upon `$T`, with `Args` already applied to the rightmost parameters of `$T`, and expecting the remaining arguments */
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;
16
- interface PartialType<$T extends Type, Applied extends unknown[], Constraints extends unknown[], Direction> extends Type {
17
- type: apply<$T, Direction extends 'left' ? [...Applied, ...ToTuple<this['arguments']>] : [...ToTuple<this['arguments']>, ...Applied]>;
18
- constraints: Constraints;
19
- arguments: unknown[];
20
- }
1
+ import { Type } from './Type';
2
+ import { apply } from './apply';
3
+ import { Slice, Subtract, ToTuple } from './utils';
4
+ export { partial, partialRight, PartialRight, $partial };
5
+ export { PartialType };
6
+ /** Return a new type based upon `$T`, with `Args` already applied, expecting the remaining arguments */
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;
8
+ /** A free version of `partial` */
9
+ interface $partial<$T extends Type> extends Type<1> {
10
+ type: _partial<$T, [this['arguments'][0]]>;
11
+ }
12
+ declare type _partial<$T extends Type, Args extends unknown[]> = PartialType<$T, Args, Slice<$T['constraints'], Args['length'], Required<$T['constraints']>['length']>, 'left'>;
13
+ /** Return a new type based upon `$T`, with `Args` already applied to the rightmost parameters of `$T`, and expecting the remaining arguments */
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;
16
+ interface PartialType<$T extends Type, Applied extends unknown[], Constraints extends unknown[], Direction> extends Type {
17
+ type: apply<$T, Direction extends 'left' ? [...Applied, ...ToTuple<this['arguments']>] : [...ToTuple<this['arguments']>, ...Applied]>;
18
+ constraints: Constraints;
19
+ arguments: unknown[];
20
+ }
package/dist/partial.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/dist/unwrap.d.ts CHANGED
@@ -1,43 +1,47 @@
1
- import { ArrayKeys, Eq, And, Extends, Not } from './utils';
2
- import { Type } from './Type';
3
- import { inferArgs } from './inferArgs';
4
- import { Generic, apply } from './apply';
5
- import { TypesMap } from './TypesMap';
6
- import { Tuple, ReadonlyTuple, Array, ReadonlyArray } from './free-types';
7
- declare type Search = Type | SearchList;
8
- declare type SearchList = Type[] | Record<string, Type> | Interface;
9
- declare type Interface = {
10
- [k: string]: any;
11
- } & {
12
- [Symbol.toStringTag]?: never;
13
- };
14
- declare global {
15
- interface SymbolConstructor {
16
- readonly toStringTag: unique symbol;
17
- }
18
- interface Symbol {
19
- readonly [Symbol.toStringTag]: string;
20
- }
21
- var Symbol: SymbolConstructor;
22
- }
23
- export { unwrap, Unwrapped, Search };
24
- /** Decompose a type into its constituents */
25
- declare type unwrap<T, From extends Search = TypesMap> = And<Extends<T, readonly unknown[]>, Not<Extends<From, Type | Type[]>>> extends true ? unwrapLists<T extends readonly unknown[] ? T : never> : _unwrap<T, From extends Type ? [From] : From>;
26
- 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]]>;
27
- declare type Mutable<T> = {
28
- -readonly [K in keyof T]: K extends ArrayKeys ? T[K] : T[K];
29
- };
30
- declare type _unwrap<T, From extends SearchList, R = {
31
- [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;
32
- }> = R[keyof R];
33
- interface Branch<T, $T extends Type, K> {
34
- match: Disambiguate<T, $T, inferArgs<T, $T>, K & string>;
35
- miss: never;
36
- }
37
- 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;
38
- /** The result of unwrapping a type with `unwrap` */
39
- declare type Unwrapped<URI extends string = string, T extends Type = Type, A = unknown[]> = {
40
- URI: URI;
41
- type: T;
42
- args: A;
43
- };
1
+ import { ArrayKeys, Eq, And, Extends, Not, IsAny } from './utils';
2
+ import { Type } from './Type';
3
+ import { inferArgs } from './inferArgs';
4
+ import { Generic, apply } from './apply';
5
+ import { TypesMap } from './TypesMap';
6
+ import { Tuple, ReadonlyTuple, Array, ReadonlyArray } from './free-types';
7
+ declare type Search = Type | SearchList;
8
+ declare type SearchList = Type[] | Record<string, Type> | Interface;
9
+ declare type Interface = {
10
+ [k: string]: any;
11
+ } & {
12
+ [Symbol.toStringTag]?: never;
13
+ };
14
+ declare global {
15
+ interface SymbolConstructor {
16
+ readonly toStringTag: unique symbol;
17
+ }
18
+ interface Symbol {
19
+ readonly [Symbol.toStringTag]: string;
20
+ }
21
+ var Symbol: SymbolConstructor;
22
+ }
23
+ export { unwrap, Unwrapped, Search };
24
+ /** Decompose a type into its constituents */
25
+ declare type unwrap<T, From extends Search = TypesMap> = IsAny<T> extends true ? Any : And<Extends<T, readonly unknown[]>, Not<Extends<From, Type | Type[]>>> extends true ? unwrapLists<T extends readonly unknown[] ? T : never> : _unwrap<T, From extends Type ? [From] : From>;
26
+ 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]]>;
27
+ declare type Mutable<T> = {
28
+ -readonly [K in keyof T]: K extends ArrayKeys ? T[K] : T[K];
29
+ };
30
+ declare type _unwrap<T, From extends SearchList, R = {
31
+ [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;
32
+ }> = R[keyof R];
33
+ interface Branch<T, $T extends Type, K> {
34
+ match: Disambiguate<T, $T, inferArgs<T, $T>, K & string>;
35
+ miss: never;
36
+ }
37
+ 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;
38
+ /** The result of unwrapping a type with `unwrap` */
39
+ declare type Unwrapped<URI extends string = string, T extends Type = Type, A = unknown[]> = {
40
+ URI: URI;
41
+ type: T;
42
+ args: A;
43
+ };
44
+ interface $Any extends Type {
45
+ type: any;
46
+ }
47
+ declare type Any = Unwrapped<'any', $Any, any>;
package/dist/unwrap.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/dist/utils.d.ts CHANGED
@@ -1,34 +1,34 @@
1
- export { Natural, Prev, Next, Subtract };
2
- export { ArrayKeys, Slice, ToTuple, Tuple, Head, Tail, Last, Init };
3
- export { Extends, Eq, And, Not, IsUnknown, IsAny, IsOptional };
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[] = []> = number extends To ? SliceOpenEndedTuple<T, From> : SliceTuple<T, From, To, I, R>;
13
- declare type SliceOpenEndedTuple<T extends unknown[], From extends number> = From extends 0 ? T : T extends [unknown, ...infer R] ? SliceOpenEndedTuple<R, Prev<From>> : never;
14
- declare type SliceTuple<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]]>;
15
- declare type IsOptional<T extends unknown[], I extends number> = [
16
- {
17
- [K in T['length'] as K]: K extends I ? never : unknown;
18
- }[I]
19
- ] extends [never] ? true : false;
20
- 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]]>;
21
- 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]>;
22
- declare type Head<T extends [unknown, ...unknown[]]> = T[0];
23
- declare type Tail<T extends [unknown, ...unknown[]]> = T extends [unknown, ...infer R] ? R : never;
24
- declare type Last<T extends unknown[]> = T[Prev<T['length']>];
25
- declare type Init<T extends [unknown, ...unknown[]]> = T extends [...infer R, unknown] ? R : never;
26
- declare type IsUnknown<T> = unknown extends T ? IsAny<T> extends false ? true : false : false;
27
- declare type IsAny<T> = Extends<T | anything, T & anything>;
28
- declare type Extends<A, B> = [A] extends [B] ? true : false;
29
- declare type Eq<A, B> = [A] extends [B] ? [B] extends [A] ? true : false : false;
30
- declare type And<A, B> = Fork<A, Fork<B, B, false>, false>;
31
- declare type Fork<P, T, F> = P extends false ? F : T;
32
- declare type Not<T> = Extends<T, false>;
33
- declare const thing: unique symbol;
34
- declare type anything = typeof thing;
1
+ export { Natural, Prev, Next, Subtract };
2
+ export { ArrayKeys, Slice, ToTuple, Tuple, Head, Tail, Last, Init };
3
+ export { Extends, Eq, And, Not, IsUnknown, IsAny, IsOptional };
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[] = []> = number extends To ? SliceOpenEndedTuple<T, From> : SliceTuple<T, From, To, I, R>;
13
+ declare type SliceOpenEndedTuple<T extends unknown[], From extends number> = From extends 0 ? T : T extends [unknown, ...infer R] ? SliceOpenEndedTuple<R, Prev<From>> : never;
14
+ declare type SliceTuple<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]]>;
15
+ declare type IsOptional<T extends readonly unknown[], I extends number> = [
16
+ {
17
+ [K in T['length'] as K]: K extends I ? never : unknown;
18
+ }[I]
19
+ ] extends [never] ? true : false;
20
+ 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]]>;
21
+ 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]>;
22
+ declare type Head<T extends [unknown, ...unknown[]]> = T[0];
23
+ declare type Tail<T extends [unknown, ...unknown[]]> = T extends [unknown, ...infer R] ? R : never;
24
+ declare type Last<T extends unknown[]> = T[Prev<T['length']>];
25
+ declare type Init<T extends [unknown, ...unknown[]]> = T extends [...infer R, unknown] ? R : never;
26
+ declare type IsUnknown<T> = unknown extends T ? IsAny<T> extends false ? true : false : false;
27
+ declare type IsAny<T> = Extends<T | anything, T & anything>;
28
+ declare type Extends<A, B> = [A] extends [B] ? true : false;
29
+ declare type Eq<A, B> = [A] extends [B] ? [B] extends [A] ? true : false : false;
30
+ declare type And<A, B> = Fork<A, Fork<B, B, false>, false>;
31
+ declare type Fork<P, T, F> = P extends false ? F : T;
32
+ declare type Not<T> = Extends<T, false>;
33
+ declare const thing: unique symbol;
34
+ declare type anything = typeof thing;
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "free-types-core",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "A type-level library enabling the creation and the manipulation of type constructors which are detached from their type parameters.",
5
5
  "keywords:": [
6
6
  "higher kinded type",