-
-
Notifications
You must be signed in to change notification settings - Fork 158
Add support for literal tuples #826
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
base: master
Are you sure you want to change the base?
Conversation
This will be a bit of a change in user experience - folks will see e.g. I haven't experienced any shift in typechecking results from having more specific Array types hanging around - while I'm sure we'll want to add more logic in the future to be better on more explicitly handling |
I'm a big fan of expanding support for tuples, but I'm a little hesitant to infer tuples from literal arrays. I have some cases in my own projects where an array that's intended to be mutable gets initialized with default elements. I'd prefer them to be inferred as This kinda makes me wish Ruby had some equivalent to Elixir's native tuple type :/ |
@castwide: In your case, would the types be varied? If not, I think I taught Chain::Array to create Array instead of Array(X, X, X, X) or what have you for something like If the types /are/ varied, apiology#4 has Array(X, Y, Z) treat Array<X, Y, Z> as its de-facto superclass, - so ideally it would degrade gracefully if you tried to mutate the array and still accept the operations. I could add some specs to explore that behavior and agree on what we want it to be and what it will take to get there. I could perhaps even find the common superclass (e.g., Array(Integer, Float) could have a "superclass" of Array). Another idea would be to treat this as a bit of a 'hidden' type - the LSP could show the Array<> types when the type is inferred, and the Array() version when the types are declared explicitly. I'll dig in a little and find out what TypeScript and Mypy do in these situations (Steep and Sorbet as well if applicable) |
That was one of the use cases that occurred to me. I might want |
That makes sense to me. I've been running with it for three weeks now and have been pretty happy with it, but I think we have options if folks want a more conservative approach too. |
No description provided.