-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Domain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsFixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do this
Milestone
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...
Metadata
Metadata
Assignees
Labels
Domain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsFixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do this