abichinger / vue-js-cron

Renderless Vue.js cron editor
MIT License
73 stars 23 forks source link

Could not find a declaration file for module '@vue-js-cron/light' #36

Closed aborba-simeon closed 11 months ago

aborba-simeon commented 11 months ago

Hey there. I have a Quasar v1.20.1 with TypeScript and I'm trying to install the vue-js-cron/light package (for Vue2, but I also tried others and Vue3), and in all attempts, I'm getting the error when importing:

Could not find a declaration file for module '@vue-js-cron/light'. '.../node_modules/@vue-js-cron/light/dist/light.umd.js' implicitly has an 'any' type.

I'm importing the package as:

// Component.vue
import cronLight from '@vue-js-cron/light';
import '@vue-js-cron/light/dist/light.css';

Here it is my package.json:

    ...
    "@vue-js-cron/light": "^1.0.5",
    "@vue/composition-api": "^0.6.4",
    "quasar": "1.20.1",

Vue version: 2.6.14 Typescript version: 4.2.2

I also tried creating the declaration as;

// types.d.ts
declare module '@vue-js-cron/light' {
  import cronLight from '@vue-js-cron/light';
  export default cronLight
}

And had no success.

Any help here is appreciated.

abichinger commented 11 months ago
// types.d.ts
declare module '@vue-js-cron/light';

This should make the default import of @vue-js-cron/light typed as any (https://stackoverflow.com/a/50516783/3140799)

Make sure types.d.ts is included: https://www.typescriptlang.org/tsconfig#include

aborba-simeon commented 11 months ago

Thanks for the fast reply. When adding the above to types.d.ts I get:

Invalid module name in augmentation. Module '@vue-js-cron/light' resolves to an untyped module at '.../node_modules/@vue-js-cron/light/dist/light.umd.js', which cannot be augmented.ts(2665)

abichinger commented 11 months ago

Sorry, but I'm not familiar with this error. The only thing I found, is that you should only declare one module per file. https://stackoverflow.com/a/42522751/3140799

e.g. create a new file types-light.d.ts

// types-light.d.ts
declare module '@vue-js-cron/light';

Do you have more stuff in types.d.ts?

aborba-simeon commented 11 months ago

@abichinger that was it, I had two more declarations indeed. Sorry I missed that.

..."augmentation" means "declaring a module in the same file with other module declaration(s)

Thank you very much for your help!