free-types-core 1.0.0 → 1.0.1

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 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<D> : never;
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<D extends Descriptor> {
35
+ interface FromTemplate<T extends {
36
+ type: any;
37
+ }, D extends Descriptor> {
37
38
  [k: number]: unknown;
38
- type: D['type'] extends infer Type ? unknown[] extends this['arguments'] ? 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 : This[I & number] extends infer Arg ? (IsOptional<Constraints, I> extends true ? Arg extends undefined ? T : Arg : Arg) : never;
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/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/package.json CHANGED
@@ -1,34 +1,34 @@
1
- {
2
- "name": "free-types-core",
3
- "version": "1.0.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.1",
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
+ }