Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
becbaile-te opened this issue Sep 28, 2023 · 1 comment
Labels

Comments

@becbaile-te
Copy link

becbaile-te commented Sep 28, 2023

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
@wallbf
Copy link

wallbf commented Nov 28, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants