Closed motiz88 closed 8 years ago
@motiz88 this looks really good, thanks. Regarding "should this check be stricter and enforce that types be exactly ["array"]?" - yes, I don't think there are any circumstances where that isn't a mistake.
@motiz88 thanks! I think your solution is correct, I'm imagining an annotation like this:
function demo (...args: Array<string>|Array<number>) {
}
@phpnode That's the thing, though. I thought so too at first, but extractAnnotationTypes()
appears to remove duplicates, which would seem to make the check overly defensive given the current code. It's robust in the sense that it won't break if a types
array with duplicates does slip through somehow, but that's really a matter of taste at this point, or rather, a question of whether extractAnnotationTypes()
is guaranteed to dedupe its result.
I think that will need some work in the near future anyway in order to support e.g. Array<number|string>
properly
As the
T
inArray<T>
is not checked right now, and the...
-to-Array
desugaring is internal to Babel, I elected to remove the runtime check here entirely and convert it to a modest static check that the annotation indeed asks for an array type.By the way, should this check be stricter and enforce that
types
be exactly["array"]
?