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
{{ message }}
Repository navigation
Tuples constructed via array literals don't typecheck against tuple constraints #3369
In this case p won't typecheck because x has been inferred as number[] instead of [number, number]. It would be really nice if the type system could check against both types.
Tuple types are not inferred from arrays, they have to be specified explicitly. so in your example:
varx: [number,number]=[1,2];
or the type alias way as you specified.
Changing how an array literal type being inferred would be a huge breaking change that would not be feasible at this point; also it is not clear if this would be more helpful than inferring an array in the general case.
I suppose at this point it could fall back to the least restrictive type, but I do see that its going to be pretty complicated (and maybe a bit unpredictable).
The problem is there is not really a fall back.. the type is either an array or a tuple.. inferring a tuple would enable some scenarios but would break others and vice versa.
In this case
pwon't typecheck because x has been inferred asnumber[]instead of[number, number]. It would be really nice if the type system could check against both types.