Closed
Description
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.
-
If a source type is a
ReadonlyArray
(for allE
), and a target type is anArray
, then give a specialized error message thatReadonlyArray
s can't be assigned toArray
s.A 'ReadonlyArray' cannot be assigned to an 'Array' because 'Array's can be mutated.
-
If the source type is a
readonly
tuple, and the target is a plain tuple or array-like type...A 'readonly' tuple cannot be assigned to a mutable 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...