yandex-maps-unofficial / vue-yandex-map

Yandex Maps Component for VueJS
MIT License
359 stars 103 forks source link

Vue3 + TypeScript = TS7016: Could not find a declaration file for module 'vue-yandex-maps' #356

Closed crazy-tosser closed 6 months ago

crazy-tosser commented 2 years ago

При попытке в компоненте сделать

import { yandexMap } from 'vue-yandex-maps' Получаю ошибку

TS7016: Could not find a declaration file for module 'vue-yandex-maps'. {{path_to_project}}/node_modules/vue-yandex-maps/dist/vue-yandex-maps.umd.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/vue-yandex-maps` if it exists or add a new declaration (.d.ts) file containing `declare module 'vue-yandex-maps';`

package.json

"dependencies": {
    "@vueuse/core": "^6.9.0",
    "axios": "^0.21.4",
    "vee-validate": "^4.5.4",
    "vue": "^3.0.0",
    "vue-class-component": "^8.0.0-0",
    "vue-router": "^4.0.12",
    "vue-yandex-maps": "^0.12.3",
    "vuex": "^4.0.2"
  },
"devDependencies": {
    "@typescript-eslint/eslint-plugin": "^4.18.0",
    "@typescript-eslint/parser": "^4.18.0",
    "@vue/cli-plugin-babel": "^4.5.15",
    "@vue/cli-plugin-eslint": "^4.5.15",
    "@vue/cli-plugin-typescript": "^4.5.15",
    "@vue/cli-service": "^4.5.15",
    "@vue/compiler-sfc": "^3.0.0",
    "@vue/eslint-config-typescript": "^7.0.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^7.20.0",
    "sass": "^1.43.4",
    "sass-loader": "^10.0.3",
    "typescript": "~4.1.5"
  },
PNKBizz commented 2 years ago

Скоро будет бета-версия плагина на TS для Vue3. Дописываю документацию

rodial commented 2 years ago

You can create file vue-yandex-maps.d.ts with

declare module 'vue-yandex-maps';
Goryyn commented 2 years ago

@rodial Please, can you be more specific?

rodial commented 2 years ago

@Goryyn In src/ create file vue-yandex-maps.d.ts with one line

declare module 'vue-yandex-maps';

It's not good solution, but removes the error and I used it

After it, if you don't want to see warnings like "Unknown html tag ymap-marker" use

import {yandexMap as YandexMap, ymapMarker as YmapMarker} from "vue-yandex-maps";

Also you can try to declare export, like

declare module 'vue-yandex-maps' {
  import {Component} from "vue";
  export const yandexMap: Component
  ...
}

...but I was too lazy for it

Information about it

daniluk4000 commented 6 months ago

Fixed with 1.x/2.x