Skip to content

Commit

Permalink
types: consistently use cb type
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jul 4, 2022
1 parent de8db14 commit e7db774
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 3 additions & 5 deletions packages/context/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import assign from 'assign';
import defaultTo from 'defaultTo';
import invariant from 'invariant';
import optionalFunctionValue from 'optionalFunctionValue';
import { CB } from 'utilityTypes';

// eslint-disable-next-line max-lines-per-function
export function createContext<T extends Record<string, unknown>>(
init?: (ctxRef: Partial<T>, parentContext: T | void) => T | null
): {
run: <R>(ctxRef: Partial<T>, fn: (context: T) => R) => R;
bind: <Fn extends (...args: any[]) => any>(ctxRef: Partial<T>, fn: Fn) => Fn;
bind: <Fn extends CB>(ctxRef: Partial<T>, fn: Fn) => Fn;
use: () => T | undefined;
useX: (errorMessage?: string) => T;
} {
Expand Down Expand Up @@ -47,10 +48,7 @@ export function createContext<T extends Record<string, unknown>>(
return res;
}

function bind<Fn extends (...args: any[]) => any>(
ctxRef: Partial<T>,
fn: Fn
) {
function bind<Fn extends CB>(ctxRef: Partial<T>, fn: Fn) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - this one's pretty hard to get right
const returnedFn: Fn = function (...runTimeArgs: Parameters<Fn>) {
Expand Down
4 changes: 2 additions & 2 deletions packages/n4s/src/runtime/genEnforceLazy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mapFirst from 'mapFirst';
import optionalFunctionValue from 'optionalFunctionValue';
import { Stringable } from 'utilityTypes';
import { CB, Stringable } from 'utilityTypes';

import eachEnforceRule from 'eachEnforceRule';
import { ctx } from 'enforceContext';
Expand Down Expand Up @@ -83,7 +83,7 @@ export type Lazy = LazyRules &
LazyRuleMethods &
// This is a "catch all" hack to make TS happy while not
// losing type hints
Record<string, (...args: any[]) => any>;
Record<string, CB>;

type LazyRuleMethods = LazyRuleRunners & {
message: (message: LazyMessage) => Lazy;
Expand Down
4 changes: 3 additions & 1 deletion packages/shared/src/callEach.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default function callEach(arr: ((...args: any[]) => any)[]): void {
import { CB } from 'utilityTypes';

export default function callEach(arr: CB[]): void {
return arr.forEach(fn => fn());
}
2 changes: 1 addition & 1 deletion packages/shared/src/utilityTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export type DropFirst<T extends unknown[]> = T extends [unknown, ...infer U]

export type Stringable = string | ((...args: any[]) => string);

export type CB = (...args: any[]) => void;
export type CB = (...args: any[]) => any;

export type ValueOf<T> = T[keyof T];

1 comment on commit e7db774

@vercel
Copy link

@vercel vercel bot commented on e7db774 Jul 4, 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-next-ealush.vercel.app
vest-next.vercel.app
vest-next-git-latest-ealush.vercel.app
vest-website.vercel.app

Please sign in to comment.