typescript中 import type { xxx } from 'vue'是什么意思

vue-cli@next脚手架中生成的shims-vue.d.ts文件,

declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default component
}

这里的import type是什么意思?是将interface DefineComponent转换为type DefineComponent嘛?假如是这个意思的话,是什么意义呢?

-------------更新

image
使用import type 导致eslint 的 prettier报错请问怎么解决

阅读 18.7k
4 个回答
declare module '*.vue' {
  import type { DefineComponent } from 'vue' //import DefineComponent类型 
  const component: DefineComponent<{}, {}, any> //声明component为DefineComponent类型
  export default component;//默认导出变量
}
Importing Types
Prior to TypeScript 3.8, you can import a type using import. With TypeScript 3.8, you can import a type using the import statement, or using import type.

`// Re-using the same import
import { APIResponseType } from "./api";

// Explicitly use import type
import type { APIResponseType } from "./api";`

安装 eslint-plugin-vue, 然后 .eslintrc.js 文件加一项配置:

module.exports = {
  parser: 'vue-eslint-parser'
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题