Skip to content

Commit

Permalink
use ts-toolbelt typing system
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed Aug 12, 2019
1 parent b87b0d3 commit 5683b3b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-expression-eval",
"version": "2.0.1",
"version": "2.0.2",
"description": "evaluate a json described boolean expression using dynamic functions",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -47,5 +47,7 @@
"tslint": "^5.18.0",
"typescript": "^3.5.3"
},
"dependencies": {}
"dependencies": {
"ts-toolbelt": "^3.7.1"
}
}
10 changes: 3 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

import {O as tObject} from 'ts-toolbelt';

export type PropertyCompareOp<C, K extends keyof C> = C[K];

export type FuncCompareOp<C, F extends FunctionsTable<C>, K extends keyof F> = Parameters<F[K]>[0];
Expand Down Expand Up @@ -52,13 +54,7 @@ export interface NotCompareOp<C, F extends FunctionsTable<C>> {
not: Expression<C, F>;
}

export type RequireOnlyOne<T, Keys extends keyof T = keyof T> =
Pick<T, Exclude<keyof T, Keys>>
& {
[K in Keys]-?:
Required<Pick<T, K>>
& Partial<Record<Exclude<Keys, K>, undefined>>
}[Keys];
export type RequireOnlyOne<T extends object> = tObject.Either<T, keyof T>;

export type Expression<C, F extends FunctionsTable<C>> = NotCompareOp<C, F> | OrCompareOp<C, F> | AndCompareOp<C, F> |
RequireOnlyOne<CompareOp<C, F>>;
Expand Down

0 comments on commit 5683b3b

Please sign in to comment.