You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's a valid grammatical production, but not valid according to the type system. The grammar is about what's syntactically valid, not necessarily semantically valid (the same way that var x: number = 'foo' is allowed by the grammar, but not allowed by the type system).
We perhaps could change the rule from "a rest parameter must be an array type" to "a rest parameter must be an array type or a union type in which all constituents are array types" but that seems not worth adding complexity for, since it's easy enough to add overloads to clarify the intended behavior:
// Either thisfunctionDoIt1(...v: string[]): void;functionDoIt1(...v: number[]): void;functionDoIt1(...v: any[]): void{}// Or maybe this is what you meant?functionDoIt2(...v: Array<number|string>): void{}
According to the spec (see later in this note), the following should be valid:
but this gives an error:
I'm guessing this is therefore an error in the spec?
The text was updated successfully, but these errors were encountered: