Recommended Typescript definitions for Phoenix Javascript library

Hi, I’m relatively new to Phoenix and Typescript, and ran into a problem. The type definitions installed in the “@types/phoenix” npm package ( don’t include the “params” property on the Channel object. I kind of need that property, but when I use it Typescript throws a bunch of errors.

What’s the recommended approach for using Phoenix’s JS library from Typescript? Is there a different type definition package I should use, or do most people just copy type definitions from somewhere else into their own code? Is there another approach I don’t see?

Thanks! As I said, I’m new to this ecosystem, so if I missed some documentation go ahead and just link it.

1 Like

If the types in this package are wrong, please submit a PR! I’ve done so myself in the past and it’s not terribly hard to do, and it’ll get accepted pretty fast.

To answer your question though, no I am not aware of any other typescript types for Phoenix.

Ha, well, part of the problem is that I’m not experienced enough to know if the problem is really with the type definitions or some kind of user error.

But if DefinitelyTyped really is the canonical source, I guess the options are user error or pull request.

For posterity: it was user error. I guess you’re not supposed to directly assign to channel.params anymore, but pass a closure to the Channel constructor that returns up-to-date params when called.

Anyway, the definitions in @types/phoenix are correct AFAICT.