Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement in typescript? #96

Closed
osdiab opened this issue Mar 8, 2020 · 12 comments
Closed

Implement in typescript? #96

osdiab opened this issue Mar 8, 2020 · 12 comments

Comments

@osdiab
Copy link

osdiab commented Mar 8, 2020

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.

@osdiab
Copy link
Author

osdiab commented Mar 8, 2020

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

@osdiab
Copy link
Author

osdiab commented Mar 9, 2020

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.

@osdiab
Copy link
Author

osdiab commented Mar 9, 2020

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.

@osdiab
Copy link
Author

osdiab commented Mar 9, 2020

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

@osdiab
Copy link
Author

osdiab commented Mar 9, 2020

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

@matthewp
Copy link
Owner

matthewp commented Mar 9, 2020

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.

@matthewp
Copy link
Owner

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

@HartS
Copy link

HartS commented Jan 6, 2024

I know this is a few years old, but I've been banging my head against xstate for about a week now. I found the docs for robot and was excited to have found a simpler and more straightforward alternative!

Alas, in 2024, using a project without first-class Typescript support is out of the question for me. Regardless, thank you for the wonderful library... if I ever take on another project where type-safety isn't critical, I'm looking forward to trying it out!

@matthewp
Copy link
Owner

matthewp commented Jan 9, 2024

Robot has types. What problems are you having with them?

@HartS
Copy link

HartS commented Jan 9, 2024

Thanks @matthewp , I hadn't found anything in the docs about Typescript support, so assumed it didn't have it.

I just took a look at the code though and the types look simple enough to work with that I think I could figure things out from the source (the xstate types on the other hand... are very dense). I'm mainly wondering about things like type hinting for state names, context, etc. since I've found native-JS projects to be a bit weaker than native-TS projects as a generalization.

I think once I finish ironing out my initial machine definitions in xstate I'll take a stab at implementing in Robot also to see how it compares; I suspect Robot will be much easier to work with (but perhaps at the cost of flexibility and feature-set, which is understandable given different project goals)

@THOUSAND-SKY
Copy link

I would like to have types for send, it should autocomplete all possible transitions.

const [current, send] = useMachine(machine);
send("autocomplete me please")

@matthewp
Copy link
Owner

@THOUSAND-SKY coming in #232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants