Verified against @stacksjs/stx at 0.2.153 (local build of main, HEAD 0dcb6fbd0e).
TL;DR
The ambient declaration for useSearchParams() is wrong in both directions: it promises two methods that do not exist at runtime, and omits two that do.
| Member | Declared (stx.d.ts:111-116) | Runtime (src/signals.ts:1085) |
|---|---|---|
get | ✅ | ✅ |
set | ✅ | ✅ |
delete | ✅ | ❌ absent |
has | ✅ | ❌ absent |
setAll | ❌ not declared | ✅ present |
data | ❌ not declared | ✅ present (the backing signal) |
Declared
packages/stx/stx.d.ts:111 (hand-written; copied verbatim to dist/stx.d.ts):
declare function useSearchParams(): {
get: (key: string) => string | null
set: (key: string, value: string) => void
delete: (key: string) => void
has: (key: string) => boolean
}Implemented
packages/stx/src/signals.ts:1085:
return {
data: params,
get: function(key) { return params()[key]; },
set: function(key, value) { … },
setAll: function(obj) { … }
};Why it matters
useSearchParams is in STX_AUTO_IMPORTS (src/client-script.ts:316), so a <script client> block gets it as an ambient global and the declaration is the only contract an author sees.
const params = useSearchParams()
params.delete('q') // type-checks; TypeError at runtime: params.delete is not a function
params.has('q') // type-checks; TypeError at runtime
params.setAll({...}) // works at runtime; TS2339 "Property 'setAll' does not exist"The two failure directions are both bad, but the first is worse: the compiler actively endorses a call that throws in the browser.
Suggested fix
Either add delete / has to the runtime object, or correct the declaration to match what is returned. If the declaration is the thing that changes:
declare function useSearchParams(): {
data: StxSignal<Record<string, string>>
get: (key: string) => string | undefined
set: (key: string, value: string) => void
setAll: (values: Record<string, string>) => void
}Note get returns params()[key], i.e. undefined for a missing key — not null as declared.
Related
Same class of defect as #1707 / #1796 / #1797 — a shipped declaration disagreeing with the implementation it describes — but a distinct symbol and a distinct fix. Found alongside two others I am filing separately (navigate, useCookie).