Pinelab-studio / pinelab-vendure-plugins

Monorepo for different Vendure plugins developed by Pinelab
111 stars 49 forks source link

chartist.component.ts typescript error when building the UI #525

Closed taxilian closed 1 month ago

taxilian commented 1 month ago

Which plugin/repository is the issue about? metrics

Describe the bug When trying to build the admin UI I get:

admin-ui/src/extensions/eb6e1994381aaf6a1ded134203bba73449900d8a1578974a2f65ce3958c246ad/chartist/chartist.component.ts(47,35): error TS2345: Argument of type 'undefined[] | ChartEntry' is not assignable to parameter of type 'ChartEntry'.
  Type 'undefined[]' is missing the following properties from type 'ChartEntry': summary, formatOptions
admin-ui/src/extensions/eb6e1994381aaf6a1ded134203bba73449900d8a1578974a2f65ce3958c246ad/chartist/chartist.component.ts(110,53): error TS2345: Argument of type 'undefined[] | ChartEntry' is not assignable to parameter of type 'ChartEntry'.
  Type 'undefined[]' is not assignable to type 'ChartEntry'.

To Reproduce Steps to reproduce the behavior:

Using Vendure 3.0.5 and typescript@5.3.3 trying to compile a custom admin UI.

Expected behavior No errors

Screenshots image

Environment

typescript 5.3.3

Additional context

It is possible that there is something unusual about how I'm building my custom UI, but everything else has been working.

taxilian commented 1 month ago

Digging into the source code this looks like typescript is actually catching a real bug. The line is:

      this.chart.update(this.entriesToLineChartData(this.entries ?? []));

entriesToLineChartData takes a ChartEntry and immediately tries to use entry.summary?.labels?.length – since summary won't exist on an empty array this will technically work, but it's confusing at best. It would probably make more sense to have entriesToLineChartData aware that entry could be undefined, then always just pass in this.entries – which should also know that it could possibly be undefined.

taxilian commented 1 month ago

FWIW my tsconfig parameters are:

 {
   "compilerOptions": {
    "allowJs": true,
    "module": "CommonJS",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "ES2022",
    "useDefineForClassFields": false,
    "strict": false,
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "resolveJsonModule": true,
    "strictPropertyInitialization": false,
    "skipLibCheck": true
  },
}