fix: allow user-defined interfaces as Server Props#412
Open
mattzcarey wants to merge 1 commit into
Open
Conversation
Interfaces do not get implicit index signatures in TypeScript, so the Record<string, unknown> bound on Props rejected them with 'Index signature for type string is missing' (surfaced downstream as cloudflare/agents#1886). Bound Props by 'object' on Server, getServerByName, and routePartykitRequest. The T constraints on the latter two become Server<Env, object>: the #_props private field carries Props covariantly, so a subclass declaring interface Props failed the old Server<Env> constraint, and the DO stub's setName param resolved to the constraint's Record type. Defaults stay Record<string, unknown> so untyped usage still reads props values as unknown.
🦋 Changeset detectedLatest commit: de5bc27 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
hono-party
partyfn
partyserver
partysocket
partysub
partysync
partytracks
partywhen
y-partyserver
commit: |
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.
Summary
The
Propsgeneric onServer,getServerByName, androutePartykitRequestwas bounded byRecord<string, unknown>. Interfaces do not get implicit index signatures in TypeScript, so a well-typed interface fails that bound with:This surfaced downstream as cloudflare/agents#1886 (
getAgentByName(ns, name, { props: config })rejecting interface-typed props) — the agents SDK inherits these bounds throughServerandgetServerByName, so the root fix belongs here.Fix —
objectbounds, noany, no castsProps extends object = Record<string, unknown>onServer,getServerByName, androutePartykitRequest. Interfaces satisfyobjectnatively; defaults stayRecord<string, unknown>so untyped usage still reads props values asunknown. Props is only ever treated as an opaque JSON bag at runtime (encodeProps/decodePropsalready type itunknown), so nothing behavioral changes.T extends Server<Env, object> = Server<Env>ongetServerByName/routePartykitRequest. Two things forced this: the#_propsprivate field carriesPropscovariantly, so a subclass declaring interface Props failed the oldServer<Env>constraint (whose Props silently pinned to theRecorddefault); and the DO stub'ssetNameparameter resolves from the constraint, sooptions.propswouldn't flow without it. The default staysServer<Env>, keeping the return type for untyped callers identical.Repro / regression tests
New compile-time test
packages/partyserver/src/tests/props.test-d.ts— typechecked bycheck:typebut never executed (vitest only picks up*.test.ts). Written first and confirmed red on main with errors matching the report:Serverdeclared with interfacePropsgetServerByName/routePartykitRequestcalled with interface-typed propsonStartreceiving the interface typePropsVerification
npm run build && npm run checkfully green (sherif, oxfmt, oxlint, all 42 typecheck projects, all workspace test suites).Once this ships, cloudflare/agents can bump
partyserverand loosen its ownPropsbounds without any bridging (supersedes the approach in cloudflare/agents#1906, closed in favor of fixing it here).