question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: Vue2 Legacy missing typescript definitions

See original GitHub issue

Would you like to work on a fix?

  • Check this if you would like to implement a PR, we are more than happy to help you go through the process.

Current and expected behavior

Following the example on https://vue-chartjs.org/guide/#creating-your-first-chart I run into an issue with typescript:

Could not find a declaration file for module 'vue-chartjs/legacy'. '.../node_modules/vue-chartjs/legacy/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/vue-chartjs` if it exists or add a new declaration (.d.ts) file containing `declare module 'vue-chartjs/legacy';`Vetur(7016)

Unfortunatley there are no types for this project available at https://github.com/DefinitelyTyped/DefinitelyTyped

I could solve this issue by using vue-chartjs@3.5.1.

Reproduction

https://vue-chartjs.org/guide/#creating-your-first-chart

chart.js version

3.7.1

vue-chartjs version

4.0.6

Possible solution

Add type definitions for the legacy package of vue-chartjs

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Santobertcommented, May 19, 2022

@thabarbados thanks for the quick fix. Types are there now and at least the bar chart works flawlessly (as far as I can see). Unfortunately chart types other than the bar chart cannot be used as Vue components.

Minimal example:

<template>
  <div>
    <LineChartGenerator
      :chart-options="chartOptions"
      :chart-data="chartData"
      chart-id="line-chart"
      dataset-id-key="label"
    />
  </div>
</template>

<script lang="ts">
import { Chart, registerables } from "chart.js";
import Vue from "vue";
import { Line as LineChartGenerator } from "vue-chartjs/legacy";

Chart.register(...registerables);

export default Vue.extend({
  components: { LineChartGenerator },
  data() {
    return {
      chartData: {
        labels: [
          "January",
          "February",
          "March",
          "April",
          "May",
          "June",
          "July",
        ],
        datasets: [
          {
            label: "Data One",
            backgroundColor: "#f87979",
            data: [40, 39, 10, 40, 39, 80, 40],
          },
        ],
      },
      chartOptions: {
        responsive: true,
        maintainAspectRatio: false,
      },
    };
  },
});
</script>

grafik

Funny thing is that while the error is reported, you can see the rendered chart in the background.

grafik

index.d.ts

grafik

2reactions
yooozcommented, May 24, 2022

@glennpierce

Sorry, I don’t have any idea how you can try my repository easily.

But I can tell you my way

  1. clone and build my vue-chartjs repository
    1. build command is pnpm build and please check emitted index.d.ts
  2. replace your/project/node_modules/vue-chartjs/index.d.ts and yoooz/vue-chartjs/index.dts

Even if yoooz/vue-chartjs add your package.json , installing only yoooz/vue-chartjs/package.json only . I think easily install my commit if my pull request merged.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript - adding typing to custom Vue2 plugin: "File is not a ...
I get this second error, which I believe just means that the declaration file is not being parsed (because changes in it do...
Read more >
TypeScript Support - Vue I18n - Intlify
If you compile typescript in this state, you will get the following error to check that no ja-JP resource is defined in the...
Read more >
@types/vue | Yarn - Package Manager
This is a stub types definition for vuejs (https://github.com/vuejs/vue). vuejs provides its own type definitions, so you don't need @types/vue installed!
Read more >
ts-loader - npm
TypeScript loader for webpack. Latest version: 9.4.2, last published: 25 days ago. Start using ts-loader in your project by running `npm i ...
Read more >
CLI Service - Vue CLI
[entry] in the CLI command is defined as the entry file (default: src/main.js or src/main.ts in TypeScript project), not an additional entry ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found