sevensidedmarble
Since static typing is all the rage in Elixir right now, maybe some of you will appreciate my most recent video. It’s all about how to get started with TypeScript in your Phoenix apps (assuming you’re using the default esbuild).
Let me know if you have any suggestions for further videos!
Trending in Screencasts
Plotto is a 100% Elixir charting library with no NIFs or external dependencies. In this episode, we’ll use it to add interactive SVG char...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
arcanemachine
Nice work. I love how easy Phoenix makes it to get started with TS. Literally just rename your
*.jsfiles to*.tsand ESBuild will pick them up automagically.You brought up typosquatting when you searched for the LiveView types on npm. That’s something that should be emphasized very strongly. npm is rife with malware these days, and there are a lot of packages that are waiting for people to install something with the wrong name. I always copy and paste the package name from npm, I never type it. Yes, this is probably overkill, but I don’t want to slip up and shoot myself in the foot.
With the
Property 'liveSocket' does not exist on type 'Window...'bit, I haven’t used TS in a bit and I am a bit of a noob on that subject, but I always just worked around that withwindow["liveSocket"] = liveSocket;. Not sure if that is even supposed to work, but it always did the trick for me.Again, good stuff.
sevensidedmarble
Yeah you have to be really careful with npm install for sure.
And the big advantage of properly augmenting the window type is that then other parts of your code will know that thing exists on window.
francois-codes
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
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 withthis 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
this way the argument of your event handler function will be correctly typed