Title: Error spans are not close enough to missing properties on deeply nested object literals · Issue #22170 · microsoft/TypeScript · GitHub
Open Graph Title: Error spans are not close enough to missing properties on deeply nested object literals · Issue #22170 · microsoft/TypeScript
X Title: Error spans are not close enough to missing properties on deeply nested object literals · Issue #22170 · microsoft/TypeScript
Description: TypeScript Version: all recent versions, including @next Search Terms: missing property literal error Code Consider this simplified example: type Foo = { bar: { baz: { qux: { quux: { corge: { grault: { garply: { waldo: { fred: { plugh: {...
Open Graph Description: TypeScript Version: all recent versions, including @next Search Terms: missing property literal error Code Consider this simplified example: type Foo = { bar: { baz: { qux: { quux: { corge: { graul...
X Description: TypeScript Version: all recent versions, including @next Search Terms: missing property literal error Code Consider this simplified example: type Foo = { bar: { baz: { qux: { quux: { corge: { graul...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/22170
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Error spans are not close enough to missing properties on deeply nested object literals","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨 -->\r\n\u003c!--\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker.\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the CONTRIBUTING guidelines: https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n-->\r\n\r\n\u003c!-- If you have a QUESTION:\r\n THIS IS NOT A FORUM FOR QUESTIONS.\r\n Ask questions at http://stackoverflow.com/questions/tagged/typescript\r\n or https://gitter.im/Microsoft/TypeScript\r\n-->\r\n\r\n\u003c!-- If you have a SUGGESTION:\r\n Most suggestion reports are duplicates, please search extra hard before logging a new suggestion.\r\n See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md\r\n-->\r\n\r\n\u003c!-- If you have a BUG:\r\n Please fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** all recent versions, including `@next`\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** \r\n\r\nmissing property literal error\r\n\r\n**Code**\r\n\r\nConsider this simplified example:\r\n\r\n```ts\r\ntype Foo = {\r\n bar: {\r\n baz: {\r\n qux: {\r\n quux: {\r\n corge: {\r\n grault: {\r\n garply: {\r\n waldo: {\r\n fred: {\r\n plugh: {\r\n xyzzy: {\r\n thud: {}\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nconst foo: Foo = {\r\n //^^^ error annotated here\r\n bar: {\r\n baz: {\r\n qux: {\r\n quux: {\r\n corge: {\r\n grault: {\r\n garply: {\r\n waldo: {\r\n fred: {\r\n plugh: {\r\n xyzzy: {\r\n // ... for property missing here\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n```\r\n\r\n\r\n**Expected behavior:**\r\n\r\nThe error location should be that of the innermost part of the object literal where the property is missing.\r\n\r\n**Actual behavior:**\r\n\r\nThe 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.\r\n\r\n[**Playground Link**](https://www.typescriptlang.org/play/#src=type%20Foo%20%3D%20%7B%0A%20%20%20%20bar%3A%20%7B%0A%20%20%20%20%20%20%20%20baz%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20qux%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20quux%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20corge%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20grault%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20garply%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20waldo%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20fred%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20plugh%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20xyzzy%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20thud%3A%20%7B%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0A%0Aconst%20foo%3A%20Foo%20%3D%20%7B%0A%20%20%20%20bar%3A%20%7B%0A%20%20%20%20%20%20%20%20baz%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20qux%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20quux%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20corge%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20grault%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20garply%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20waldo%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20fred%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20plugh%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20xyzzy%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D)\r\n\r\n**Context**\r\n\r\n For context, my real-world use case is typing of [Vega](https://vega.github.io/) JSON specs, which are realized programmatically as large object literals, e.g.\r\n\r\n```ts\r\nconst barChart: Spec = {\r\n $schema: 'https://vega.github.io/schema/vega/v3.json',\r\n width: 400,\r\n height: 200,\r\n padding: 5,\r\n\r\n data: [\r\n {\r\n name: 'table',\r\n values: [\r\n { category: 'A', amount: 28 },\r\n { category: 'B', amount: 55 },\r\n { category: 'C', amount: 43 },\r\n { category: 'D', amount: 91 },\r\n { category: 'E', amount: 81 },\r\n { category: 'F', amount: 53 },\r\n { category: 'G', amount: 19 },\r\n { category: 'H', amount: 87 },\r\n ],\r\n },\r\n ],\r\n\r\n signals: [\r\n {\r\n name: 'tooltip',\r\n value: {},\r\n on: [\r\n { events: 'rect:mouseover', update: 'datum' },\r\n { events: 'rect:mouseout', update: '{}' },\r\n ],\r\n },\r\n ],\r\n\r\n scales: [\r\n {\r\n name: 'xscale',\r\n type: 'band',\r\n domain: { data: 'table', field: 'category' },\r\n range: 'width',\r\n padding: 0.05,\r\n round: true,\r\n },\r\n {\r\n name: 'yscale',\r\n domain: { data: 'table', field: 'amount' },\r\n nice: true,\r\n range: 'height',\r\n },\r\n ],\r\n\r\n axes: [{ orient: 'bottom', scale: 'xscale' }, { orient: 'left', scale: 'yscale' }],\r\n\r\n marks: [\r\n {\r\n type: 'rect',\r\n from: { data: 'table' },\r\n encode: {\r\n enter: {\r\n x: { scale: 'xscale', field: 'category' },\r\n width: { scale: 'xscale', band: 1 },\r\n y: { scale: 'yscale', field: 'amount' },\r\n y2: { scale: 'yscale', value: 0 },\r\n },\r\n update: {\r\n fill: { value: 'steelblue' },\r\n },\r\n hover: {\r\n fill: { value: 'red' },\r\n },\r\n },\r\n },\r\n {\r\n type: 'text',\r\n encode: {\r\n enter: {\r\n align: { value: 'center' },\r\n baseline: { value: 'bottom' },\r\n fill: { value: '#333' },\r\n },\r\n update: {\r\n x: {\r\n scale: 'xscale',\r\n signal: 'tooltip.category',\r\n band: 0.5,\r\n },\r\n y: {\r\n scale: 'yscale',\r\n signal: 'tooltip.amount',\r\n offset: -2,\r\n },\r\n text: { signal: 'tooltip.amount' },\r\n fillOpacity: [{ test: 'datum === tooltip', value: 0 }, { value: 1 }],\r\n },\r\n },\r\n },\r\n ],\r\n};\r\n```\r\n\r\n(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.","author":{"url":"https://github.com/pelotom","@type":"Person","name":"pelotom"},"datePublished":"2018-02-24T21:58:35Z","url":"https://github.com/microsoft/TypeScript/issues/22170"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f403ef69-e818-ade1-c211-a6bf8f345f0a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C58C:1F2D:1E832E:26C704:6B00FB86 |
| html-safe-nonce | bdaef6cd134778f0d05e9e8d9f3be82253677570f64fe87b6bb2ee535df79641 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNThDOjFGMkQ6MUU4MzJFOjI2QzcwNDo2QjAwRkI4NiIsInZpc2l0b3JfaWQiOiI4MzQ1NjM2MjY1NTg4MjI2OTUwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b6f15704de768db14d5016b5d72496caab52a93dc6ae8c0ebfafaa88c8133c78 |
| hovercard-subject-tag | issue:299976313 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/22170/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4cd3890ff91f0fb4497e9549095fce43ec19ee599ccc690e57b2b047f9e6d753/microsoft/TypeScript/issues/22170 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4cd3890ff91f0fb4497e9549095fce43ec19ee599ccc690e57b2b047f9e6d753/microsoft/TypeScript/issues/22170 |
| og:image:alt | TypeScript Version: all recent versions, including @next Search Terms: missing property literal error Code Consider this simplified example: type Foo = { bar: { baz: { qux: { quux: { corge: { graul... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pelotom |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width