From d600d91205b32800d7e02dc3b60a4543e2609d85 Mon Sep 17 00:00:00 2001 From: dangreen Date: Mon, 24 Aug 2026 19:40:02 +0400 Subject: [PATCH] fix(kida): type `toAccessor` by what it actually returns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ToAccessor` and `ToAccessorOrSignal` tested `AnyAccessor`, so a function that takes an argument fell through to the wrapping branch: `toAccessor(event => …)` was typed `Accessor<(event) => …>` while it returned the callback itself, and `toAccessorOrSignal` claimed a `WritableSignal` of it. The test behind both is `isAccessor`, which is `typeof value === 'function'`. It cannot tell a callback from an accessor and hands either one back untouched, so the types now test `AnyFn` and say the same. --- packages/kida/src/internals/types.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/kida/src/internals/types.ts b/packages/kida/src/internals/types.ts index 3afb9066..2b01d74a 100644 --- a/packages/kida/src/internals/types.ts +++ b/packages/kida/src/internals/types.ts @@ -5,7 +5,7 @@ import type { WritableSignal, ReadableSignal, Accessor, - AnyAccessor + AnyFn } from 'agera' export type { AnyFn } from 'agera' @@ -40,10 +40,13 @@ export type ToSignal = [T] extends [AnyWritableSignal] ? ReadableSignal : WritableSignal> | ToSignal> -export type ToAccessor = [T] extends [AnyAccessor] +// Both of these test any function, not just a zero-argument one: the runtime +// test behind them is `typeof value === 'function'`, so a callback is handed +// back untouched exactly like an accessor is, and the type has to say the same +export type ToAccessor = [T] extends [AnyFn] ? T - : Accessor> | Extract + : Accessor> | Extract -export type ToAccessorOrSignal = [T] extends [AnyAccessor] +export type ToAccessorOrSignal = [T] extends [AnyFn] ? T - : WritableSignal> | Extract + : WritableSignal> | Extract