【问题标题】:Typescript + Vue + Element-ui打字稿 + Vue + Element-ui
【发布时间】:2018-03-11 04:46:04
【问题描述】:

如何在Vue+typescript中使用element-ui

element-ui 没有类型,所以当我导入它时

import Vue from 'vue';
import Element from 'element-ui'

我收到一个错误

Could not find a declaration file for module 'element-ui'. '/home/andres/Code/cdr/frontend/node_modules/element-ui/lib/element-ui.common.js' implicitly has an 'any' type.

我该如何解决这个问题?

【问题讨论】:

  • 你能添加你的打字稿配置吗?

标签: typescript vue.js element typescript-typings


【解决方案1】:

作为一种解决方法,您可以简单地创建自定义类型文件并声明模块:

// in element-ui.d.ts

declare module "element-ui";

这将导致您从element-ui 导入的任何内容都输入为any。当然,如果需要,您可以在 element-ui.d.ts 中添加类型定义以进行类型化。

你可以see how to write your own types here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 2021-06-20
    相关资源
    最近更新 更多