Coming from a front end dev background, I’m really happy to see a move towards typescript on Elixir 
the video is great indeed, but I was a bit annoyed that we have to use casts, satisfies, etc, to correctly type hooks. So I pushed this PR on the type package: fix(phoenix-live-view): improve phoenix liveView hooks types by francois-codes · Pull Request #71190 · DefinitelyTyped/DefinitelyTyped · GitHub
I initially thought I’d offer to add these type declarations inside the phoenix framework repo, but promptly came into an issue about this where Chris closed it saying “I have no interest about that”
so I guess it will have to live in definitely typed for now
regarding your point @arcanemachine , you need to extend the window interface like this
declare global {
interface Window {
liveSocket: LiveSocket
}
}
either include this in your app.ts file, or better, in a .d.ts file referenced in the types array of your tsconfig
This is also where you can type custom phoenix events. let’s say you’re calling push_event("custom-event", args)
on the elixir side, you’d probably define listeners on your ts code with
document.addEventListener("phx:custom-event", ({detail }) => { ... })
this will raise a type error because the event is not known to typescript. but you can use the same approach above and extend the WindowEventMap interface
interface EventPayload { ... }
declare global {
interface WindowEventMap {
'custom-event': CustomEvent<EventPayload>
}
}
this way the argument of your event handler function will be correctly typed