Update payload type in hooks and handle_event#4262
Conversation
|
Tests fail on ESLint: https://typescript-eslint.io/rules/no-wrapper-object-types/ Maybe instead of |
| alias Phoenix.LiveView.{Socket, LiveStream, Async} | ||
|
|
||
| @type unsigned_params :: map | ||
| @type unsigned_params :: term() |
There was a problem hiding this comment.
We should not change this. unsigned_params is correct as map in many places, I'd only adjust handle_event specifically.
There was a problem hiding this comment.
That's right, mount and handle_params, I overlooked. Fixing it, thanks!
There was a problem hiding this comment.
oops, I was too fast. Fixing on main!
There was a problem hiding this comment.
I'm sorry the day got busy and I wasn't able to push a follow up timely.
There was a problem hiding this comment.
No worries, all good! Thanks for sending the PR :)
|
|
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.
fbfddec to
3b8205c
Compare
|
🙌️ |
Make
pushEventandpushEventTopayload type match Phoenix'sChannel.pushtype.In JS,
Objectrefers to anything including numbers, strings, arrays, objects, and in TS it is more strict thatanywhen type checking, e.g. one cannot call arbitrary methods on it.Document that the payload must be serializable, default config is JSON.
Closes #4221.