Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k views
in Technique[技术] by (71.8m points)

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报错请问怎么解决


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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";`


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...