Skip to content

Commit

Permalink
types: simplify indirect types
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jul 25, 2022
1 parent d7d0893 commit 147c906
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
17 changes: 12 additions & 5 deletions packages/n4s/src/exports/compounds.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { enforce } from 'n4s';
import { DropFirst } from 'utilityTypes';

import { allOf } from 'allOf';
import { anyOf } from 'anyOf';
import { EnforceCustomMatcher } from 'enforceUtilityTypes';
import { Lazy } from 'genEnforceLazy';
import { noneOf } from 'noneOf';
import { oneOf } from 'oneOf';
import { RuleDetailedResult } from 'ruleReturn';

enforce.extend({ allOf, anyOf, noneOf, oneOf });

type EnforceCompoundRule = (
value: unknown,
...rules: Lazy[]
) => RuleDetailedResult;

/* eslint-disable @typescript-eslint/no-namespace */
declare global {
namespace n4s {
interface EnforceCustomMatchers<R> {
allOf: (...args: DropFirst<Parameters<typeof allOf>>) => R;
anyOf: (...args: DropFirst<Parameters<typeof anyOf>>) => R;
noneOf: (...args: DropFirst<Parameters<typeof noneOf>>) => R;
oneOf: (...args: DropFirst<Parameters<typeof oneOf>>) => R;
allOf: EnforceCustomMatcher<EnforceCompoundRule, R>;
anyOf: EnforceCustomMatcher<EnforceCompoundRule, R>;
noneOf: EnforceCustomMatcher<EnforceCompoundRule, R>;
oneOf: EnforceCustomMatcher<EnforceCompoundRule, R>;
}
}
}
10 changes: 5 additions & 5 deletions packages/n4s/src/exports/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { enforce } from 'n4s';
import { DropFirst } from 'utilityTypes';

import { EnforceCustomMatcher } from 'enforceUtilityTypes';
import { isArrayOf } from 'isArrayOf';
import { loose } from 'loose';
import { optional } from 'optional';
Expand All @@ -14,10 +14,10 @@ enforce.extend({ isArrayOf, loose, optional, shape });
declare global {
namespace n4s {
interface EnforceCustomMatchers<R> {
isArrayOf: (...args: DropFirst<Parameters<typeof isArrayOf>>) => R;
loose: (...args: DropFirst<Parameters<typeof loose>>) => R;
shape: (...args: DropFirst<Parameters<typeof shape>>) => R;
optional: (...args: DropFirst<Parameters<typeof optional>>) => R;
isArrayOf: EnforceCustomMatcher<typeof isArrayOf, R>;
loose: EnforceCustomMatcher<typeof loose, R>;
shape: EnforceCustomMatcher<typeof shape, R>;
optional: EnforceCustomMatcher<typeof optional, R>;
}
}
}
5 changes: 5 additions & 0 deletions packages/n4s/src/lib/enforceUtilityTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CB, DropFirst } from 'utilityTypes';

export type EnforceCustomMatcher<F extends CB, R> = (
...args: DropFirst<Parameters<F>>
) => R;
2 changes: 1 addition & 1 deletion packages/n4s/src/runtime/enforceEager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ export default function enforceEager(value: RuleValue): IRules {
}
}

export type EnforceEager = typeof enforceEager;
export type EnforceEager = (value: RuleValue) => IRules;
2 changes: 1 addition & 1 deletion packages/vast/src/vast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function createState(
type StateInput<S> = S | ((prevState?: S) => S);
type SetStateInput<S> = S | ((prevState: S) => S);

export type State = ReturnType<typeof createState>;
export type State = CreateStateReturn;
export type StateHandlerReturn<S> = [S, (nextState: SetStateInput<S>) => void];
export type UseState<S> = () => StateHandlerReturn<S>;

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json

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

1 comment on commit 147c906

@vercel
Copy link

@vercel vercel bot commented on 147c906 Jul 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-website.vercel.app
vest-next-ealush.vercel.app
vest-next.vercel.app
vest-next-git-latest-ealush.vercel.app

Please sign in to comment.