From 470ff9fe6de82479e0cf4a2d10223adf53c84b7b Mon Sep 17 00:00:00 2001 From: Olexii Kyrychenko Date: Thu, 20 Aug 2026 22:00:24 +0300 Subject: [PATCH] refactor: drop dead isReady/isTruthy pass-throughs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit useEffectWhenReady/useEffectWhenTruthy hand-wired isReady/isTruthy, which were one-line forwards to predicates.ready/predicates.truthy with no behavior of their own. Call the predicates directly and delete the wrapper files. UseEffectWhenPredicates moves from method syntax to property syntax so predicates.ready/truthy can be passed by reference without tripping @typescript-eslint/unbound-method. Also drops the createEffectWhen JSDoc example that showed baking predicates.ready into a factory-created hook — that pattern silently loses per-call-site tuple narrowing, since createEffectWhen fixes its generic type parameter once at creation time. --- src/createEffectWhen/createEffectWhen.ts | 9 +++++---- src/useEffectWhen/useEffectWhen.types.ts | 6 +++--- src/useEffectWhenReady/useEffectWhenReady.ts | 5 ++--- src/useEffectWhenReady/useEffectWhenReady.utils.ts | 6 ------ src/useEffectWhenTruthy/useEffectWhenTruthy.ts | 5 ++--- src/useEffectWhenTruthy/useEffectWhenTruthy.utils.ts | 7 ------- 6 files changed, 12 insertions(+), 26 deletions(-) delete mode 100644 src/useEffectWhenReady/useEffectWhenReady.utils.ts delete mode 100644 src/useEffectWhenTruthy/useEffectWhenTruthy.utils.ts diff --git a/src/createEffectWhen/createEffectWhen.ts b/src/createEffectWhen/createEffectWhen.ts index a457e7e..50182e7 100644 --- a/src/createEffectWhen/createEffectWhen.ts +++ b/src/createEffectWhen/createEffectWhen.ts @@ -24,10 +24,11 @@ import type { DependencyList } from "react"; * [user, token] * ); * - * @example — with a guard predicate for type narrowing - * const useEffectWhenReady = createEffectWhen( - * (deps): deps is ReadyDeps => predicates.ready(deps) - * ); + * NOTE: this bakes `predicate`'s deps shape in at creation time, so it fits a + * fixed deps shape reused across call sites. It's not a fit for the + * universal predicates like `predicates.ready`/`predicates.truthy` — those + * need to narrow a different deps tuple on every call, which is what + * `useEffectWhenReady`/`useEffectWhenTruthy` are for. */ export function createEffectWhen( predicate: GuardPredicate diff --git a/src/useEffectWhen/useEffectWhen.types.ts b/src/useEffectWhen/useEffectWhen.types.ts index 7d470fc..addb128 100644 --- a/src/useEffectWhen/useEffectWhen.types.ts +++ b/src/useEffectWhen/useEffectWhen.types.ts @@ -37,7 +37,7 @@ export interface UseEffectWhenOptions { } export interface UseEffectWhenPredicates { - ready(deps: T): deps is ReadyDeps; - truthy(deps: T): deps is TruthyDeps; - always(deps: T): deps is T; + ready: (deps: T) => deps is ReadyDeps; + truthy: (deps: T) => deps is TruthyDeps; + always: (deps: T) => deps is T; } diff --git a/src/useEffectWhenReady/useEffectWhenReady.ts b/src/useEffectWhenReady/useEffectWhenReady.ts index f612022..d0cce4d 100644 --- a/src/useEffectWhenReady/useEffectWhenReady.ts +++ b/src/useEffectWhenReady/useEffectWhenReady.ts @@ -1,5 +1,4 @@ -import { useEffectWhen } from "../useEffectWhen"; -import { isReady } from "./useEffectWhenReady.utils"; +import { predicates, useEffectWhen } from "../useEffectWhen"; import type { ReadyDeps, UseEffectWhenEffect, UseEffectWhenOptions } from "../useEffectWhen"; import type { DependencyList } from "react"; @@ -8,5 +7,5 @@ export function useEffectWhenReady( deps: T, options?: UseEffectWhenOptions ): void { - useEffectWhen(effect, deps, isReady, options); + useEffectWhen(effect, deps, predicates.ready, options); } diff --git a/src/useEffectWhenReady/useEffectWhenReady.utils.ts b/src/useEffectWhenReady/useEffectWhenReady.utils.ts deleted file mode 100644 index 719f50f..0000000 --- a/src/useEffectWhenReady/useEffectWhenReady.utils.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { DependencyList } from "react"; -import { ReadyDeps, predicates } from "../useEffectWhen"; - -export function isReady(deps: T): deps is ReadyDeps { - return predicates.ready(deps); -} diff --git a/src/useEffectWhenTruthy/useEffectWhenTruthy.ts b/src/useEffectWhenTruthy/useEffectWhenTruthy.ts index 44332ad..d21b9b3 100644 --- a/src/useEffectWhenTruthy/useEffectWhenTruthy.ts +++ b/src/useEffectWhenTruthy/useEffectWhenTruthy.ts @@ -1,5 +1,4 @@ -import { useEffectWhen } from "../useEffectWhen"; -import { isTruthy } from "./useEffectWhenTruthy.utils"; +import { predicates, useEffectWhen } from "../useEffectWhen"; import type { TruthyDeps, UseEffectWhenEffect, UseEffectWhenOptions } from "../useEffectWhen"; import type { DependencyList } from "react"; @@ -8,5 +7,5 @@ export function useEffectWhenTruthy( deps: T, options?: UseEffectWhenOptions ): void { - useEffectWhen(effect, deps, isTruthy, options); + useEffectWhen(effect, deps, predicates.truthy, options); } diff --git a/src/useEffectWhenTruthy/useEffectWhenTruthy.utils.ts b/src/useEffectWhenTruthy/useEffectWhenTruthy.utils.ts deleted file mode 100644 index 80d355d..0000000 --- a/src/useEffectWhenTruthy/useEffectWhenTruthy.utils.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { DependencyList } from "react"; -import { TruthyDeps } from "../useEffectWhen/useEffectWhen.types"; -import { predicates } from "../useEffectWhen/useEffectWhen.utils"; - -export function isTruthy(deps: T): deps is TruthyDeps { - return predicates.truthy(deps); -}