diegoazh / gmap-vue

A wrapper component for consuming Google Maps API built on top of Vue. Fork of the popular vue-google-maps plugin.
https://diegoazh.github.io/gmap-vue/
173 stars 51 forks source link

Need help on: TypeScript Declaration File Missing for @gmap-vue/v3 #307

Closed lunpessoa closed 7 months ago

lunpessoa commented 1 year ago

What you try to do

I am attempting to integrate the @gmap-vue/v3 library into my TypeScript project to enable Google Maps functionality.

What is the problem

The TypeScript compiler is failing to locate the declaration file for the module '@gmap-vue/v3'. The error message indicates that the file 'project/node_modules/@gmap-vue/v3/dist/main.es.js' implicitly has an 'any' type, even though there are types available at 'node_modules/@gmap-vue/v3/dist/types/src/main.d.ts'.

What kind of things have you already treated

I have verified the correctness of the path specified in the "typings" field of the package.json. I have also updated TypeScript to the latest version, but the issue persists.

Steps to reproduce

To reproduce the issue:

  1. Install the @gmap-vue/v3 library in a TypeScript project.
  2. Attempt to import the module in a TypeScript file.
  3. Observe the TypeScript error regarding the missing declaration file.

OS

Mobile

Versions

Package manager

Plugin version

create-issue-branch[bot] commented 11 months ago

Branch issue-307-Need_help_on_TypeScript_Declaration_File_Missing_for_gmap-vue/v3 created!

basuneko commented 10 months ago

@lunpessoa I've also had this issue. I think the types' exports may be a little crooked and don't work great with some TS configurations. I've found that only moduleResolution: node more-or-less works out of the box; moduleResolution: bundler gives the same error you've shared (likely because resolvePackageJsonExports is true in this mode).

The TypeScript compiler is failing to locate the declaration file for the module '@gmap-vue/v3'. The error message indicates that the file 'project/node_modules/@gmap-vue/v3/dist/main.es.js' implicitly has an 'any' type, even though there are types available at 'node_modules/@gmap-vue/v3/dist/types/src/main.d.ts'.

As a workaround, I've managed to fix this issue by adding the types entry to the package.json's exports:

diff --git a/node_modules/@gmap-vue/v3/package.json b/node_modules/@gmap-vue/v3/package.json
  "exports": {
     ".": {
+      "types": "./dist/types/src/main.d.ts"
       "import": "./dist/main.es.js",
       "require": "./dist/main.umd.js",
       "default": "./dist/main.es.js"
     }
   },

For the time being, I'm using patch-package; however, it would be nice to merge this into the repo.

diegoazh commented 8 months ago

A new version is coming soon, with breaking changes, but with a big improvement in the plugin API and its types 💪🏼.

diegoazh commented 8 months ago

Hi @lunpessoa and @basuneko, our new version has landed, could you test it (v 2.0.0)? also, you can find the main points on our new documentation site.

diegoazh commented 7 months ago

I'm going to close this but, if you find something wrong related to this ticket feel free to re-open it or open a new one if something new appears. Thank you.