-
Notifications
You must be signed in to change notification settings - Fork 2
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
Types of Rest and Spread #5
Comments
|
As far as rest is concerned: function doSomethingWithNumber(...numbers Number) {} As far as array values, I'm would think this is easier: function doSomethingWithNumber(numbers Number[]) {} Go does this (not that we should do this): function doSomethingWithNumber(numbers []Number) {} The Type gets into template/overloading territory, doesn't it? I would think a tool like Babel could handle this at build time. Doing it in the engine would be tricky without strict typing. |
The only downside to |
And if type is an expression, which would be quite powerful, it would be invalid syntax. |
Okay, now I've played about with it a bit, that makes sense.
Yes. This. It would allow something like |
I'm saying that if |
Exactly, that's what I was getting at. The ternary is just a place holder for "any expression", so that example would be syntactically valid nonsense. |
Good point. Extends allows "any expression" though. But I think in this case allowing "any expression" may be disastrous. |
(refs #30): I think this falls out of scope. If at some point in the future, the tool/linter creators ask for casting, then we can revisit the issue, or create a new spec. Closing for now. |
Oops, that last comment was supposed to be on the casting issue (I was typing in the wrong window). Regarding this issue: Do we want to hint the container type (Uint8Array), or the type of the elements? |
Type of the elements. So |
Okay, sounds good in the case of same type elements. Do we want something for multi type args? Or is function fn(...args Object) {}
fn(1, "2", {three: 3}); // linter is happy |
That would actually fail because function fn(...args) {}
fn(1, "2", {three: 3}); // linter is happy If a type hint is provided all of those must be of that type. If a type hint is omitted then it's considered mixed. |
Good point. Okay, TODO is to add |
I can see four choices:
Array<Type>
Type
Type
Array
(orArgument
), so just use:Array
The text was updated successfully, but these errors were encountered: