free-types-core 1.0.0 → 1.0.2
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/From.d.ts +13 -10
- package/dist/Type.d.ts +2 -2
- package/dist/helpers.d.ts +6 -1
- package/dist/unwrap.d.ts +2 -1
- package/package.json +34 -34
package/dist/From.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { NamedConstraints } from './Type';
|
|
1
|
+
import { Contra, NamedConstraints } from './Type';
|
|
2
2
|
import { ArrayLike, Next, IsOptional, Mappable, Union2Tuple, Int } from './utils';
|
|
3
3
|
export { From };
|
|
4
4
|
type Named = ({
|
|
5
5
|
[k: PropertyKey]: string;
|
|
6
6
|
} | undefined)[];
|
|
7
|
+
type None = {};
|
|
7
8
|
/** Create a new `Type` based upon a Mappable `T`.
|
|
8
9
|
*
|
|
9
10
|
* Optionally take a tuple `Args` to specify which fields to turn into a parameter and in what order they must be applied. Parameters can be set to be optional. Named parameters are created automatically for object types, they can be renamed.
|
|
@@ -12,35 +13,37 @@ type Named = ({
|
|
|
12
13
|
type From<T extends Mappable<any>, Args extends readonly (keyof T | undefined)[] | Named = never> = ([
|
|
13
14
|
Args
|
|
14
15
|
] extends [never] ? (T extends unknown[] ? GetIndices<T> : Union2Tuple<keyof T>) extends infer K ? {
|
|
15
|
-
type: T;
|
|
16
16
|
constraints: PseudoTuple<T, K>;
|
|
17
|
-
names:
|
|
17
|
+
names: None;
|
|
18
18
|
keys: K;
|
|
19
19
|
} : never : Args extends Named ? {
|
|
20
|
-
type: T;
|
|
21
20
|
constraints: ToConstraints<T, Args>;
|
|
22
21
|
names: GetNames<Args>;
|
|
23
22
|
keys: GetKeys<Args>;
|
|
24
23
|
} : {
|
|
25
|
-
type: T;
|
|
26
24
|
constraints: PseudoTuple<T, Args>;
|
|
27
25
|
names: Args extends (string | undefined)[] ? GenerateNames<Args> : {};
|
|
28
26
|
keys: Required<Args>;
|
|
29
|
-
}) extends infer D extends Descriptor ? FromTemplate<
|
|
27
|
+
}) extends infer D extends Descriptor ? FromTemplate<{
|
|
28
|
+
type: T;
|
|
29
|
+
}, D> : never;
|
|
30
30
|
type Descriptor = {
|
|
31
|
-
type: any;
|
|
32
31
|
constraints: any;
|
|
33
32
|
names: any;
|
|
34
33
|
keys: any;
|
|
35
34
|
};
|
|
36
|
-
interface FromTemplate<
|
|
35
|
+
interface FromTemplate<T extends {
|
|
36
|
+
type: any;
|
|
37
|
+
}, D extends Descriptor> {
|
|
37
38
|
[k: number]: unknown;
|
|
38
|
-
type:
|
|
39
|
+
type: T['type'] extends infer Type ? unknown[] extends this['arguments'] ? Type : {
|
|
39
40
|
[K in keyof Type]: Value<Type[K], this['arguments'], IndexOf<K, D['keys']>, D['constraints']>;
|
|
40
41
|
} : never;
|
|
41
42
|
namedConstraints: NamedConstraints<D>;
|
|
42
43
|
names: D['names'];
|
|
43
44
|
constraints: D['constraints'];
|
|
45
|
+
contra: Contra<D['constraints']>;
|
|
46
|
+
arg: any;
|
|
44
47
|
arguments: unknown[];
|
|
45
48
|
}
|
|
46
49
|
type GetIndices<T extends unknown[]> = {
|
|
@@ -48,7 +51,7 @@ type GetIndices<T extends unknown[]> = {
|
|
|
48
51
|
};
|
|
49
52
|
export type Value<T, This extends ArrayLike, I, Constraints extends ArrayLike> = [
|
|
50
53
|
I
|
|
51
|
-
] extends [never] ? T :
|
|
54
|
+
] extends [never] ? T : IsOptional<Constraints, I> extends true ? This[I & number] extends undefined ? T : This[I & number] : This[I & number];
|
|
52
55
|
export type IndexOf<T, Ts extends ArrayLike, L = Required<Ts>['length'], I = 0> = I extends L ? never : [T] extends [`${Ts[I & number]}`] ? I : IndexOf<T, Ts, L, Next<I>>;
|
|
53
56
|
type PseudoTuple<T, Keys> = {
|
|
54
57
|
[K in keyof Keys]: Exclude<T[Keys[K] & keyof T], undefined>;
|
package/dist/Type.d.ts
CHANGED
|
@@ -59,9 +59,9 @@ type _Type = {
|
|
|
59
59
|
};
|
|
60
60
|
};
|
|
61
61
|
type Arg<This extends _Type, Args = This['names'] & This['constraints'], O extends PropertyKey = FindOptionalKeys<This['constraints'], This['names']>, R extends PropertyKey = Exclude<Norm<Exclude<keyof Args, ArrayKeys>>, O>> = {
|
|
62
|
-
[K in Norm<R>]: ArgVal<This, K>;
|
|
62
|
+
[K in Norm<R> as `${K & number}` | K]: ArgVal<This, K>;
|
|
63
63
|
} & {
|
|
64
|
-
[K in Norm<O>]?: ArgVal<This, K>;
|
|
64
|
+
[K in Norm<O> as `${K & number}` | K]?: ArgVal<This, K>;
|
|
65
65
|
};
|
|
66
66
|
type FindOptionalKeys<Constraints, Names, O = Int<OptionalKeys<Constraints>>> = O | (keyof {
|
|
67
67
|
[K in keyof Names as Names[K] extends O ? K : never]: never;
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Next, IsUnknown, Prev, OptionalKeys } from './utils';
|
|
2
|
-
export { Get, At, Checked, Lossy, Optional, A, B, C, D, E, Applied };
|
|
2
|
+
export { Get, At, Checked, Lossy, Optional, A, B, C, D, E, Applied, Valid };
|
|
3
3
|
/** Fake `Type` for user friendly error messages */
|
|
4
4
|
interface Type<In extends number | Names> extends BaseType {
|
|
5
5
|
arg: Constraints<In>;
|
|
@@ -34,6 +34,11 @@ type Normalise<Index extends string | number> = Index extends number ? Next<Inde
|
|
|
34
34
|
type Applied<This extends {
|
|
35
35
|
arguments: any;
|
|
36
36
|
}> = unknown[] extends This['arguments'] ? false : true;
|
|
37
|
+
/** tell whether a Type is applied with all the correct arguments */
|
|
38
|
+
type Valid<This extends {
|
|
39
|
+
arguments: any;
|
|
40
|
+
constraints: any;
|
|
41
|
+
}> = Applied<This> extends false ? false : This['arguments'] extends This['constraints'] ? true : false;
|
|
37
42
|
/** safely index `this` */
|
|
38
43
|
type Get<K extends keyof This['arg'], This extends {
|
|
39
44
|
arg: any;
|
package/dist/unwrap.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { inferArgs } from './inferArgs';
|
|
|
4
4
|
import { Generic, _apply, _Type } from './apply';
|
|
5
5
|
import { TypesMap } from './TypesMap';
|
|
6
6
|
import { Tuple, ReadonlyTuple, Array, ReadonlyArray } from './free-types';
|
|
7
|
+
type ArrayURIs = 'Tuple' | 'ReadonlyTuple' | 'Array' | 'ReadonlyArray';
|
|
7
8
|
type Search = _Type | SearchList;
|
|
8
9
|
type SearchList = _Type[] | Record<string, _Type> | Interface;
|
|
9
10
|
type Interface = {
|
|
@@ -22,7 +23,7 @@ declare global {
|
|
|
22
23
|
}
|
|
23
24
|
export { unwrap, Unwrapped, Search };
|
|
24
25
|
/** Decompose a type into its constituents */
|
|
25
|
-
type unwrap<T, From extends Search = TypesMap
|
|
26
|
+
type unwrap<T, From extends Search = Omit<TypesMap, ArrayURIs>> = IsAny<T> extends true ? Any : (T extends readonly unknown[] ? From extends _Type | _Type[] ? null : unwrapLists<T> : null) extends infer R extends Unwrapped ? R : _unwrap<T, From extends _Type ? [From] : From>;
|
|
26
27
|
type unwrapLists<T extends readonly unknown[]> = T extends unknown[] ? any[] extends T ? Unwrapped<'Array', Array, [T[0]]> : Unwrapped<'Tuple', Tuple, T> : readonly any[] extends T ? Unwrapped<'ReadonlyArray', ReadonlyArray, [T[0]]> : Unwrapped<'ReadonlyTuple', ReadonlyTuple, Mutable<T>>;
|
|
27
28
|
type Mutable<T> = {
|
|
28
29
|
-readonly [K in keyof T]: T[K];
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "free-types-core",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A type-level library enabling the creation and the manipulation of type constructors which are detached from their type parameters.",
|
|
5
|
-
"keywords:": [
|
|
6
|
-
"higher kinded type",
|
|
7
|
-
"type constructor",
|
|
8
|
-
"typescript"
|
|
9
|
-
],
|
|
10
|
-
"main": "./dist/index.js",
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"files": [
|
|
13
|
-
"dist/*"
|
|
14
|
-
],
|
|
15
|
-
"author": "Geoffrey Gourdet",
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "https://github.com/geoffreytools/free-types-core"
|
|
19
|
-
},
|
|
20
|
-
"license": "ICS",
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"foo": "github:geoffreytools/Foo",
|
|
23
|
-
"ts-spec": "^1.7.0",
|
|
24
|
-
"ts-trace": "github:geoffreytools/ts-trace",
|
|
25
|
-
"typescript": "^4.9.5"
|
|
26
|
-
},
|
|
27
|
-
"scripts": {
|
|
28
|
-
"watch build": "tsc -p ./tsconfig-build.json --watch",
|
|
29
|
-
"watch test": "tsc --watch",
|
|
30
|
-
"build": "tsc -p ./tsconfig-build.json",
|
|
31
|
-
"trace": "bash ./node_modules/ts-trace/ts-trace.sh -i ./tsconfig-perf.json",
|
|
32
|
-
"diagnostics": "tsc -p ./tsconfig-perf.json --extendedDiagnostics"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "free-types-core",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "A type-level library enabling the creation and the manipulation of type constructors which are detached from their type parameters.",
|
|
5
|
+
"keywords:": [
|
|
6
|
+
"higher kinded type",
|
|
7
|
+
"type constructor",
|
|
8
|
+
"typescript"
|
|
9
|
+
],
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist/*"
|
|
14
|
+
],
|
|
15
|
+
"author": "Geoffrey Gourdet",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/geoffreytools/free-types-core"
|
|
19
|
+
},
|
|
20
|
+
"license": "ICS",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"foo": "github:geoffreytools/Foo",
|
|
23
|
+
"ts-spec": "^1.7.0",
|
|
24
|
+
"ts-trace": "github:geoffreytools/ts-trace",
|
|
25
|
+
"typescript": "^4.9.5"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"watch build": "tsc -p ./tsconfig-build.json --watch",
|
|
29
|
+
"watch test": "tsc --watch",
|
|
30
|
+
"build": "tsc -p ./tsconfig-build.json",
|
|
31
|
+
"trace": "bash ./node_modules/ts-trace/ts-trace.sh -i ./tsconfig-perf.json",
|
|
32
|
+
"diagnostics": "tsc -p ./tsconfig-perf.json --extendedDiagnostics"
|
|
33
|
+
}
|
|
34
|
+
}
|