matthewp / robot

🤖 A functional, immutable Finite State Machine library

Home Page:https://thisrobot.life

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement in typescript?

osdiab opened this issue · comments

Would you be opposed to a PR that implements the library directly in TypeScript with an extra build step? It would ensure that the typings stay up to date and as exhaustive as it can be and add a level of safety to the actual library code. Wanted to ask before I put any time trying to do something like that.

#75 an example that wouldn’t happen with this approach.

I'd also love this since the current typings are pretty general, i could just edit those to make them more thorough but i wouldn't feel as confident to their correctness if it's not typechecked against the actual code.

The one place where it would be problematic as far as I can tell is the overload of createMachine because the two function signatures are not mutually compatible, which unless there's a method I don't know of, would lead to messier parameter names (stateOrContextFn, that kinda thing). Otherwise everything else looks easily portable - except for a few potentially mistyped things at the moment, like empty() being treated as a ContextFn but not actually matching the declared type.

the other thing that makes this a pain in the ass in a quick 30 min attempt is that there's extensive use of this and not pretty abstract helpers in the implementation, making things pretty confusing

yah i think im gonna abandon this for now or maybe just make a fork that does this stuff in a more straightforward manner for my own edification lol

I don't think I'd rewrite in TypeScript because I don't use TypeScript myself. The typing files have served us well so far, so I don't see an issue with it. Since this library isn't going to change in radical ways we don't need to worry about the typings becoming wrong in the future.

Going to close this, a TS rewrite is extremely unlikely at this time.