-
Notifications
You must be signed in to change notification settings - Fork 38
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
Array types #96
Comments
Should we reuse the existing JS syntax—rest parameters—for zero or more?
I consider this the main use case.
Typed arrays (shouldn't be confused with TypedArray)
Regular expression |
Actually, I have a feeling that ES 2015 rather sees the const myItems = [a, b, c];
fun(...myItems) ≅ fun(a, b, c);
[...myItems, d] ≅ [a, b, c, d]; So I don’t see that as a problem. All in all, I really like your idea. More than the regex-inspired syntax proposed by @ericelliott, to be honest. To a newcomer, |
If we go down the regex path, it gets tricky to parse too. Consider something like: [((Number|String){3,}, Function){2,5}] I don’t think anyone would need such a monster. So let’s KISS (don’t get me wrong 😃). |
Who doesn't know regular expressions, yes.
You are probably right. It's used with objects as well after all. At this point I would like 0 or more The only remaining issue is 1 or more. Would |
I actually like |
How about:
|
I dunno what the others think, but IMO it's brillant and obvious. Ashamed I didn't think of it. |
I don't hate this: [...Type] instead of [Type*]
[Type...] instead of [Type+] And I don't think it could be a slippery slope like introducing regex features.. ;) |
Ill make a PR to support this proposal this week. It will just be examples/descriptions without corresponding sub sections hence avoiding naming things inappropriately. |
When you do, make it clear that We frequently have a need to document collection polymorphisms ... see Lodash |
@ericelliott You can commit on the branch Ill create: I can't possibly describe stuff I don't comprehend. |
@Mouvedia It means, for example, that you can do this: interface Collection: Object | Array
highPass(cutoff: Number, collection: Collection[...Number]) => numbers: [...Number] Collection polymorphism is very common in JavaScript, and we should have an easy way to deal with it. See also Generics and Collection Polymorphism from"Programming JavaScript Applications". |
@ericelliott The usage of brackets for that use case seems to make sense since it's limited to objects (arrays included). But still why not I like to limit the scope of the additions to the specification so that there's less friction in the process. |
Because it's a generic function. It works for both arrays and objects. The point of using I'd open a new issue, but we have already discussed generics in depth in several other issues, and generics and typed arrays are deeply interconnected. Any array syntax we adopt should use the generic syntax that we decide to go with, for internal consistency. This is why I favor the square bracket syntax for generics. |
Yeah I think we should continue this discussion on #80. I consider "typed arrays" a consensual subject, illustrated by the fact that we easily converged to a common solution. |
No,
either. Not to mention the fact that you didn't declare the interface
|
I think we lost the signal here. What we're discussing, unless I'm missing something, is a new syntax for how the spread operator is interpreted in the context of the square bracket notation for generic invocations. In this context, I mean that the bracket notation, The spread operator in this context means the same thing whether
Thus Unless I'm mistaken, whether zero or more or one or more is default when you specify |
That's exactly what I was trying to avoid. The issues regarding generics should be discussed on #80. |
@Mouvedia As I have mentioned several times, generics and typed arrays are inextricably linked -- and that's a feature, because it enables the easy expression of collection polymorphism. |
@ericelliott I don't deny this. It may be or may not. What I want is adding what covers the main use case to the specification. If it happens to fit in the bigger picture of what's gonna be added next then all the better. But Iv seen you changing your mind over the syntax of generics. You were at one time supporting whitespace. I am being practical that's all. Small iterations FTW. |
@Mouvedia Point taken. I'm open to a PR for |
The text was updated successfully, but these errors were encountered: