let point = [3, 4] as const;
function distanceFromOrigin([x, y]: [number, number]) {
return Math.sqrt(x ** 2 + y ** 2);
}
distanceFromOrigin(point);
Argument of type 'readonly [3, 4]' is not assignable to parameter of type '[number, number]'.
Type 'readonly [3, 4]' is missing the following properties from type '[number, number]': pop, push, reverse, shift, and 6 more.
This is bad to show to beginners. Here's a few things we could be doing better.
This is bad to show to beginners. Here's a few things we could be doing better.
If a source type is a
ReadonlyArray(for allE), and a target type is anArray, then give a specialized error message thatReadonlyArrays can't be assigned toArrays.If the source type is a
readonlytuple, and the target is a plain tuple or array-like type...If one side is a tuple type, and the other isn't array-like, just don't elaborate at all. Nobody cares about missing
push,pop, and 6 other members...