Skip to content

fix(pi): accept typed connection hooks in pi() - #354

Merged
eersnington merged 1 commit into
mainfrom
fix/pi-conn-hook-types
Oct 14, 2026
Merged

eersnington merged 1 commit into
mainfrom
fix/pi-conn-hook-types

Conversation

@eersnington

Copy link
Copy Markdown
Member

pi() constrained TUserActions with PiUserActions<...>. TypeScript did not infer the connection state type from createConnState through that constraint, so app actions saw c.conn.state and connection params without their types and needed casts.

Now the actions in the config are typed through an intersection with UserActions<...>, and TUserActions is a plain Record<string, unknown>. The action's c takes its type from the config, so c.conn.state has the type that createConnState returns:

const agent = pi({
	registry: createRegistry(),
	createConnState: async (_c, params: { token: string }) => {
		const user = users.get(params.token);
		if (!user) throw new UserError("Bad token.", { code: "unauthorized" });
		return { userId: user.id };
	},
	actions: {
		// No cast: c.conn.state is { userId: string }.
		whoami: (c): string => c.conn.state.userId,
	},
});
  • actor-types.ts: actions?: TUserActions & UserActions<TState, TConnParams, TConnState, ...>.
  • actor.ts: TUserActions extends Record<string, unknown> in PiActorConfigInput and pi().
  • tests/connection-hooks.test.ts: a bad token is rejected on a built-in call, and a good token connects and the app's action reads c.conn.state.

@railway-app

railway-app Bot commented Oct 13, 2026

Copy link
Copy Markdown

This PR was not deployed automatically as @eersnington does not have access to the Railway project.

In order to get automatic PR deploys, please add @eersnington to your workspace on Railway.

@eersnington
eersnington force-pushed the fix/pi-conn-hook-types branch from 18a5a14 to c5cdfba Compare October 14, 2026 00:57
@eersnington
eersnington merged commit a0e7bb7 into main Oct 14, 2026
3 checks passed
@eersnington
eersnington deleted the fix/pi-conn-hook-types branch October 14, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant