The goal is pretty straight forward, since typed arrays have a fixed length it would be a more accurate and helpful type it you could specify length. Then you could get complaints if you try to assign or access a higher index or use a array of the incorrect length.
Code
typeVector2d=Int32Array<2>;typeVector3d=Int32Array<3>;typeMatrix=Int32Array<16>;constadd=(vecA:Vector2d)=>(vecB:Vector2d,target:Vector2d=newInt32Array(2)):Vector2d=>{target[0]=vecA[0]+vecB[0];target[1]=vecA[1]+vecB[1];returntarget;};constadd3d=(vecA:Vector3d)=>(vecB:Vector3d,target:Vector3d=newInt32Array(3)):Vector3d=>{target[0]=vecA[0]+vecB[0];target[1]=vecA[1]+vecB[1];target[2]=vecA[2]+vecB[2];returntarget;};constposition=newInt32Array(2);constposition3d=newInt32Array(3);constvelocity=newInt32Array([1,1]);constvelocity3d=newInt32Array([1,2,3]);add(position)(velocity,position);constnewPosition=add(position)(velocity);add3d(position3d)(velocity3d,position3d);add(position3d)(velocity3d,position3d);// Fails due to incorrect array length
The goal is pretty straight forward, since typed arrays have a fixed length it would be a more accurate and helpful type it you could specify length. Then you could get complaints if you try to assign or access a higher index or use a array of the incorrect length.
Code