【问题标题】:How to use vue-twemoji-picker with TypeScript?如何在 TypeScript 中使用 vue-twemoji-picker?
【发布时间】:2021-03-24 06:42:42
【问题描述】:

我正在尝试在我的 Vue + TypeScript 项目中使用 vue-twemoji-picker,但出现以下错误。我该如何解决这个问题?

7:31 Could not find a declaration file for module '@kevinfaguiar/vue-twemoji-picker'. '/Users/owner/WebstormProjects/audilet/node_modules/@kevinfaguiar/vue-twemoji-picker/dist/vue-twemoji-picker.umd.min.js' implicitly has an 'any' type.
  Try `npm install @types/kevinfaguiar__vue-twemoji-picker` if it exists or add a new declaration (.d.ts) file containing `declare module '@kevinfaguiar/vue-twemoji-picker';`
     5 | 
     6 | <script lang="ts">
  >  7 | import { TwemojiPicker } from '@kevinfaguiar/vue-twemoji-picker';
       |                               ^
     8 | import {Component, Prop, Vue} from "vue-property-decorator";
     9 | 
    10 | @Component

我尝试了yarn add -D @types/kevinfaguiar__vue-twemoji-picker,但它返回未找到。 (vue-twemoji-picker 项目的仓库中有tsconfig.json 和*.d.ts 文件,所以我认为不需要这个操作。)

我的代码:

<template>
  <div>test</div>
</template>
<script lang="ts">
import { TwemojiPicker } from '@kevinfaguiar/vue-twemoji-picker';
import {Component, Prop, Vue} from "vue-property-decorator";

@Component
export default class SampleComponent extends Vue {
}
</script>

【问题讨论】:

    标签: typescript vue.js


    【解决方案1】:

    我认为您正在使用的包不会为导出的内容生成类型。以下是您可以检查包是否具有内置类型的一些内容:

    • 在根目录中有一个index.d.ts 文件,代表包的输入

    • 或者打字可以放在不同的目录,但在这种情况下,它必须在package.json文件中的typings属性中解决,例如:

    package.json

    {
      "typings": "typings/index.d.ts",
    }
    

    简而言之,如果您无法看到以上 2 项内容,则可以断定一个没有内置类型的包。所以你必须自己定义,或者通过@types repo 寻找它。

    【讨论】:

      猜你喜欢
      • 2020-05-26
      • 1970-01-01
      • 2017-06-28
      • 2019-02-02
      • 2017-05-29
      • 2021-09-13
      • 2022-01-06
      • 2017-06-22
      • 2020-07-14
      相关资源
      最近更新 更多