Skip to content

Update payload type in hooks and handle_event#4262

Merged
SteffenDE merged 2 commits into
phoenixframework:mainfrom
rhcarvalho:pushEvent-payload-type
Jun 3, 2026
Merged

Update payload type in hooks and handle_event#4262
SteffenDE merged 2 commits into
phoenixframework:mainfrom
rhcarvalho:pushEvent-payload-type

Conversation

@rhcarvalho

Copy link
Copy Markdown
Contributor

Make pushEvent and pushEventTo payload type match Phoenix's Channel.push type.

In JS, Object refers to anything including numbers, strings, arrays, objects, and in TS it is more strict that any when type checking, e.g. one cannot call arbitrary methods on it.

Document that the payload must be serializable, default config is JSON.

Closes #4221.

@rhcarvalho

Copy link
Copy Markdown
Contributor Author

Comment thread lib/phoenix_live_view.ex
alias Phoenix.LiveView.{Socket, LiveStream, Async}

@type unsigned_params :: map
@type unsigned_params :: term()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not change this. unsigned_params is correct as map in many places, I'd only adjust handle_event specifically.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, mount and handle_params, I overlooked. Fixing it, thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, I was too fast. Fixing on main!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry the day got busy and I wasn't able to push a follow up timely.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, all good! Thanks for sending the PR :)

@SteffenDE

Copy link
Copy Markdown
Member

unknown sounds good to me!

Phoenix's `Channel.push` declares the payload type as `Object` (treated
as a generic interface that covers all JS values).

In JS, `Object` refers to anything including numbers, strings, arrays,
objects, and in TS it is more strict that `any` when type checking, e.g.
one cannot call arbitrary methods on it.

Make `pushEvent` and `pushEventTo` payload type match, preferring
`unknown` over `Object` to satisfy
https://typescript-eslint.io/rules/no-wrapper-object-types/ and
https://typescript-eslint.io/rules/no-explicit-any#alternatives-to-any.

Document that the payload must be serializable, default config is JSON.
@rhcarvalho rhcarvalho force-pushed the pushEvent-payload-type branch from fbfddec to 3b8205c Compare June 3, 2026 11:06
@SteffenDE SteffenDE merged commit c6c6f01 into phoenixframework:main Jun 3, 2026
8 checks passed
@SteffenDE

Copy link
Copy Markdown
Member

🙌️

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.

Inconsistent payload type definition in pushEvent / pushEventTo

2 participants