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

Documentation for Typescript usage needs to highlight that the spec should be declared "as const". #9317

Open
unphased opened this issue Apr 21, 2024 · 0 comments

Comments

@unphased
Copy link

See the following comment. Until I saw this explanation I was going crazy looking for how to import types like AnyMark, which typescript was trying to tell me my "bar" mark type was invalid for.

import {compile} from 'vega-lite';

const vegaLiteSpec = {
  $schema: 'https://vega.github.io/schema/vega-lite/v4.json',
  data: {
    values: [
      {a: 'A', b: 28},
      {a: 'B', b: 55},
      {a: 'C', b: 43},
      {a: 'D', b: 91},
      {a: 'E', b: 81},
      {a: 'F', b: 53},
      {a: 'G', b: 19},
      {a: 'H', b: 87},
      {a: 'I', b: 52}
    ]
  },
  mark: 'bar',
  encoding: {
    x: {field: 'a', type: 'nominal', axis: {labelAngle: 0}},
    y: {field: 'b', type: 'quantitative'}
  }
} as const;

const vegaSpec = compile(vegaLiteSpec).spec;

The issue without as const is that Typescript widens the type of "bar" to string rather than the literal "bar".

Originally posted by @domoritz in #7127 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant