Error spans are not close enough to missing properties on deeply nested object literals #22170
Labels
Bug
A bug in TypeScript
Domain: Error Messages
The issue relates to error messaging
Effort: Moderate
Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".
Fixed
A PR has been merged for this issue
Help Wanted
You can do this
Milestone
TypeScript Version: all recent versions, including
@next
Search Terms:
missing property literal error
Code
Consider this simplified example:
Expected behavior:
The error location should be that of the innermost part of the object literal where the property is missing.
Actual behavior:
The location is reported on the variable being assigned to. The pain of this is exacerbated dramatically if each of the intervening levels of nesting has lots of other properties too. It becomes incredibly laborious to find the real source of the problem.
Playground Link
Context
For context, my real-world use case is typing of Vega JSON specs, which are realized programmatically as large object literals, e.g.
(This is a relatively small example as Vega specs go.) If any of the required properties at a deeply nested level is missing, the
spec
variable is annotated with the error, and one has to hunt through the long error message to discover where the actual problem lies.The text was updated successfully, but these errors were encountered: