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
exportinterfaceVector{x:number;y:number;}typePoint=[number,number];constVectors: Vector[]=[];// Error in the affectationconstpoints:Array<Point>=Vectors.map((Vector)=>{return[Vector.x,Vector.y];});// This is workingconstpointsOk:Array<Point>=Vectors.map((Vector)=>{return<Point>[Vector.x,Vector.y];});
Expected behavior:
The compiler should understand I am returning a tuple and not an array of values Actual behavior:
I get an error and need to cast the conversion to get the right behaviour
I think the compiler should infer [1, 2] as [number, number], and allow [number, number] to be assigned to number[]. The same should hold for [1, 'a'] being inferred as [number, string] which should be allowed to be assigned to (number | string)[].
Activity
w0rp commentedon Jul 25, 2017
I have just encountered this same issue myself.
I think the compiler should infer
[1, 2]as[number, number], and allow[number, number]to be assigned tonumber[]. The same should hold for[1, 'a']being inferred as[number, string]which should be allowed to be assigned to(number | string)[].RyanCavanaugh commentedon Jul 25, 2017
See #11924 (comment) / #10195