NightCatSama / vue-slider-component

🌡 A highly customized slider component
https://nightcatsama.github.io/vue-slider-component
MIT License
2.39k stars 341 forks source link

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

Open becbaile-te opened 9 months ago

becbaile-te commented 9 months ago

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.

https://github.com/NightCatSama/vue-slider-component/blob/061e4f4afeb103d9727b58d1fabca486809472e7/lib/typings/index.d.ts#L78

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)

wallbf commented 7 months ago

我遇到同样的问题 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.