feat: infer query/command argument types from the handler signature#2
Merged
Merged
Conversation
Allow declaring query, query.batch, query.live and command with a bare handler whose parameter type becomes the client-side argument type — no schema, no 'unchecked'. The value passes through unvalidated (there is no trust boundary locally); the one-argument rule and stable-JSON cache keys are unchanged. form still requires a schema or 'unchecked' since FormData needs coercion/validation. Documented as a new difference in DIFFERENCES.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EJj9ab3v9HjudgX8L1x821
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Allows declaring
query,query.batch,query.liveandcommandwith just a handler — the client-side callable gets the exact same signature as the handler's parameter, type-checked by TypeScript, with no runtime validation:SvelteKit can't offer this because remote-function arguments cross a network trust boundary; locally the handler and caller live in the same bundle, so the handler's signature is authoritative.
Semantics
'unchecked'. Schema and'unchecked'declarations are unchanged (kit parity preserved).formis excluded: form data comes from the DOM as strings and needs coercion + validation, so forms still require a schema or'unchecked'.fn.length: zero-parameter handlers stay argument-less (the dev-time guard against accidental arguments is kept). Documented caveat: handlers with only default/rest parameters ((arg = {}) => ...) have length 0 and are treated as argument-less.Implementation
parse_declaration()insrc/lib/validation.tsis the single choke point all factories flow through: a bare handler withfn.length >= 1now maps to'unchecked'. This activates the feature forquery,commandandquery.livewith no factory changes.query.batchadditionally accepts the bare-handler form (create_query_batchnow usesparse_declaration; a batch handler always takes the args array, so a bare declaration simply means unvalidated).query/query.batch/query.live(insrc/lib/query/index.ts) andcommand(insrc/lib/command.svelte.ts), placed after the existing no-argument overloads so zero-param handlers keep resolving toLocalQueryFunction<void, Output>.Docs & tests
queryandcommand" with rationale and the arity caveat; README examples updated; playground switched to the inferred form forgetLikes/addLike.@ts-expect-errorcompile-time assertions.Verification
svelte-check: 0 errors / 0 warnings ·vitest: 103/103 ·svelte-package+publint: clean🤖 Generated with Claude Code
https://claude.ai/code/session_01EJj9ab3v9HjudgX8L1x821
Generated by Claude Code