Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error spans are not close enough to missing properties on deeply nested object literals #22170

Closed
pelotom opened this issue Feb 24, 2018 · 5 comments
Assignees
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

Comments

@pelotom
Copy link

pelotom commented Feb 24, 2018

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: {
                                            xyzzy: {
                                                thud: {}
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

const foo: Foo = {
    //^^^ error annotated here
    bar: {
        baz: {
            qux: {
                quux: {
                    corge: {
                        grault: {
                            garply: {
                                waldo: {
                                    fred: {
                                        plugh: {
                                            xyzzy: {
                                              // ... for property missing here
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

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.

const barChart: Spec = {
  $schema: 'https://vega.github.io/schema/vega/v3.json',
  width: 400,
  height: 200,
  padding: 5,

  data: [
    {
      name: 'table',
      values: [
        { category: 'A', amount: 28 },
        { category: 'B', amount: 55 },
        { category: 'C', amount: 43 },
        { category: 'D', amount: 91 },
        { category: 'E', amount: 81 },
        { category: 'F', amount: 53 },
        { category: 'G', amount: 19 },
        { category: 'H', amount: 87 },
      ],
    },
  ],

  signals: [
    {
      name: 'tooltip',
      value: {},
      on: [
        { events: 'rect:mouseover', update: 'datum' },
        { events: 'rect:mouseout', update: '{}' },
      ],
    },
  ],

  scales: [
    {
      name: 'xscale',
      type: 'band',
      domain: { data: 'table', field: 'category' },
      range: 'width',
      padding: 0.05,
      round: true,
    },
    {
      name: 'yscale',
      domain: { data: 'table', field: 'amount' },
      nice: true,
      range: 'height',
    },
  ],

  axes: [{ orient: 'bottom', scale: 'xscale' }, { orient: 'left', scale: 'yscale' }],

  marks: [
    {
      type: 'rect',
      from: { data: 'table' },
      encode: {
        enter: {
          x: { scale: 'xscale', field: 'category' },
          width: { scale: 'xscale', band: 1 },
          y: { scale: 'yscale', field: 'amount' },
          y2: { scale: 'yscale', value: 0 },
        },
        update: {
          fill: { value: 'steelblue' },
        },
        hover: {
          fill: { value: 'red' },
        },
      },
    },
    {
      type: 'text',
      encode: {
        enter: {
          align: { value: 'center' },
          baseline: { value: 'bottom' },
          fill: { value: '#333' },
        },
        update: {
          x: {
            scale: 'xscale',
            signal: 'tooltip.category',
            band: 0.5,
          },
          y: {
            scale: 'yscale',
            signal: 'tooltip.amount',
            offset: -2,
          },
          text: { signal: 'tooltip.amount' },
          fillOpacity: [{ test: 'datum === tooltip', value: 0 }, { value: 1 }],
        },
      },
    },
  ],
};

(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.

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Feb 26, 2018
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 2.8 milestone Feb 26, 2018
@DanielRosenwasser DanielRosenwasser added Help Wanted You can do this Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". labels Feb 26, 2018
@Kingwl
Copy link
Contributor

Kingwl commented Feb 28, 2018

is this issue in community milestone?

@DanielRosenwasser
Copy link
Member

It's not clear if we can even fix this without a decent amount of code complexity, since the error can be very non-local, but it's worth a shot. If you'd like to send a PR, we'd appreciate it!

@DanielRosenwasser DanielRosenwasser changed the title Error markers are not localized properly for missing properties on deeply nested object literals Error spans are not close enough to missing properties on deeply nested object literals Feb 28, 2018
@mhegazy mhegazy modified the milestones: TypeScript 2.8, TypeScript 2.9 Mar 9, 2018
@mhegazy mhegazy removed this from the TypeScript 2.9 milestone Apr 26, 2018
@mhegazy mhegazy added this to the Community milestone Apr 26, 2018
@mhegazy mhegazy added the Domain: Error Messages The issue relates to error messaging label Apr 26, 2018
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jul 28, 2018

I think that @weswigham fixed this in TypeScript 3.0 (#25030 bug and #25140 for fix).

@DanielRosenwasser
Copy link
Member

image

@pelotom
Copy link
Author

pelotom commented Jul 29, 2018

Thanks, this is great to hear!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

6 participants