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
A simpler interface for react-move #54
Comments
I think react-move is too flexible to have meaningful defined types. To me, the most valuable thing has been you suggesting a way to allow the user to define their own types. I don't know Typescript and had no idea that was even possible. That's what we should get out there, the built in types are going to fall short no matter what we do. Here's what I think makes sense, let the user supply their own types and "override" the existing types. There's a bunch of edge cases here that will make the intersection between user defined and built in types not workable. I think we should provide some loose types that provide some basic type safety but then let the user override for their case. Not sure on the syntax but something like this...
Here's a sketch of what i think would work What do you think? |
I think we are nearly on the same page, I don't think we need the As far as namespaces go, is it always the case that you either don't have namespaces:
Or you do have namespaces:
But never:
If it is either you have namespaces or not then this covers that scenario |
One deceptive thing about typescript and return types is you lose excess property checking on the return type of callbacks. I came across this while trying to do this and wrote a blog post about it. This can give the illusion of type safety with extra properties not being type checked. |
Great. Just an FYI. On the namespaces, the examples you gave are NOT correct...
Should be...
You also absolutely could have a mixed case. That's why I made a mixed case the example in the link I sent above. To make it clear that you have to handle those types of cases.
|
@sghall great, these are useful examples. |
@sghall I think there is no sane way of defining the namespace and object to have the same type in typescript currently. I was well down the path of insanity there before I had a moment of sense. If the user wants to use namespaces then they define that in their ts interface. e.g. No namespace:
Namespace
Here is an updated version that still has widening problems which I can look at but is a whole lot easier |
Yeah, Typescript is just not made for this. I think, what you sent is too opinionated to be the default and we seem to be going around in circles. To me, I keep saying there's a separate "State" and "Config" type and you keep sending back ideas where there's just the "State" type because it fits the narrow case you're thinking about or because Typescript can't deal with more dynamic types (really not sure). I think we can get around this with the solution below. In any case, we have to allow namespaces and arrays of config objects out of the box (this also not covered in your examples, right?). People will come back here and complain if the stuff shown in the docs have typescript errors by default. An idea: Just completely forget about real type safety by default in react-move:All in this example
Move all of this to user land:
Is there anything that couldn't be made reasonably type safe doing it this way? |
Yep. This has become unproductive. Sorry. Not going to deal with it. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
For posterity, @sghalls recommendations work just fine. It shouldn't be the expectation that users can rely 100% on the types of a library when the structure of those types can dynamically change due to user code. It's reasonable for React Move to provide types for the interfaces it can control and unfortunately that's the most reliability we can offer. Once an isolated piece of code (like this library) calls into user-land code, user-land types will be necessary. I think this is a great testament to why TS provides value while also creating new problems. |
i've been having a playabout with react-move and I think we can simplify things down to the example on this typescript playground.
By letting the user supply their bits we can concentrate on the config.
Let me know what you think.
The text was updated successfully, but these errors were encountered: