NightCatSama/vue-slider-component

[vue3.x] Errors during type checking because of default export in `index.d.ts`

becbaile-te opened this issue · 1 comments

Describe the bug

We are using this component in our design system library and ran into type errors in our own repo and in our consumer repos that we traced back to this line.

export default VueSlider

In short, importing a Vue component in a .d.ts file did not allow that file to be excluded from type checking with vue-tsc, and we saw errors like this one.

> npx vue-tsc --project tsconfig.gen-dts.json --noEmit

node_modules/vue-slider-component/lib/utils/control.ts:554:22 - error TS6133: 'pos' is declared but its value is never read.

554     dotsPos.forEach((pos, i) => {
                         ~~~


Found 1 error in node_modules/vue-slider-component/lib/utils/control.ts:554

In our library, we fixed this issue by overriding index.d.ts with our own vue-slider-component.d.ts file that exports the type Vue.ComponentOptions<Vue> as the default export rather than the component itself. https://012.vuejs.org/api/options.html

import Vue from 'vue';

declare module 'vue-slider-component' {
    export default Vue.ComponentOptions<Vue>;

   ... everything else from lib/typings/index.d.ts
}

In tsconfig.json:

"compilerOptions": {
   ...
    "paths": {
        "vue-slider-component": ["./src/types/vue-slider-component.d.ts"]
    }
}

If this is an issue for anyone else, I would recommend updating this export in the .d.ts file to export a Vue component type rather than the component instance. Since this is a small change, I'm happy to open this PR if it is helpful.

Environment (If you feel unrelated, please delete the block)

  • OS & Version: macOS
  • Vue version: v3.2.0
  • Component Version: v4.1.0-beta.7

我遇到同样的问题
node_modules/vue-slider-component/lib/utils/control.ts:554:22 - error TS6133: 'pos' is declared but its value is never read.

554 dotsPos.forEach((pos,i) => {
~~~

src/views/schedule/components/addOrEditModal.vue:258:33 - error TS6133: 'rule' is declared but its value is never read.