bherbruck / svelte-echarts

Apache ECharts wrapper for Svelte
https://bherbruck.github.io/svelte-echarts/
MIT License
91 stars 6 forks source link

Typescript errors for the example code #5

Closed palises closed 12 months ago

palises commented 1 year ago

I've installed the library and copy/pasted the code and I get the following typescript error: [{ "resource": "/Users/pablo/Desktop/Coding Projects/SvelteKit Weekly/src/routes/chart/+page.svelte", "owner": "_generated_diagnostic_collection_name_#0", "code": "2322", "severity": 8, "message": "Type '{ xAxis: { data: string[]; type: string; }; yAxis: { type: string; }; series: { data: number[]; type: string; }[]; }' is not assignable to type 'EChartsOption'.\n Types of property 'xAxis' are incompatible.\n Type '{ data: string[]; type: string; }' is not assignable to type 'XAXisOption | XAXisOption[] | undefined'.\n Type '{ data: string[]; type: string; }' is not assignable to type '(ValueAxisBaseOption & { gridIndex?: number | undefined; gridId?: string | undefined; position?: CartesianAxisPosition | undefined; offset?: number | undefined; categorySortInfo?: OrdinalSortInfo | undefined; } & { ...; }) | ... 4 more ... | XAXisOption[]'.\n Type '{ data: string[]; type: string; }' is not assignable to type 'CategoryAxisBaseOption & { gridIndex?: number | undefined; gridId?: string | undefined; position?: CartesianAxisPosition | undefined; offset?: number | undefined; categorySortInfo?: OrdinalSortInfo | undefined; } & { ...; }'.\n Type '{ data: string[]; type: string; }' is not assignable to type 'CategoryAxisBaseOption'.\n Types of property 'type' are incompatible.\n Type 'string' is not assignable to type '\"category\"'.", "source": "ts", "startLineNumber": 22, "startColumn": 10, "endLineNumber": 22, "endColumn": 17 }]

Is there anything I'm doing wrong or has something changed since svelte-echarts was last updated?

suciptoid commented 1 year ago

try this:

  import type { EChartsOption } from 'echarts';
  const options = {
    xAxis: {
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
      type: 'category'
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'bar'
      }
    ]
  } satisfies EChartsOption;
bherbruck commented 12 months ago

fixed in https://github.com/bherbruck/svelte-echarts/commit/725eb9fbf1c999f1b21b08ff76d14bba93e86ccb