shims.tsx.d.ts 文件在 Vue-Typescript 项目中有什么作用?

本文介绍了shims.tsx.d.ts 文件在 Vue-Typescript 项目中有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 typescript 创建 Vue 项目时,包含两个声明文件:shims-vue.d.ts 和 shims.tsx.d.ts.

When creating a Vue project with typescript, two declaration files are included: shims-vue.d.ts and shims.tsx.d.ts.

//shims-vue.d.ts
declare module "*.vue" {
  import Vue from 'vue';
  export default Vue;
}
还有:

//shims.tsx.d.ts
import Vue, { VNode } from 'vue';

declare global {
  namespace JSX {
    // tslint:disable no-empty-interface
    interface Element extends VNode {}
    // tslint:disable no-empty-interface
    interface ElementClass extends Vue {}
    interface IntrinsicElements {
      [elem: string]: any;
    }
  }
}
在创建一个小项目(没有 Vue CLI)时,我忘记包含第二个 (shims.tsx.d.ts),我的项目按预期编译

你可能感兴趣的:(vue.js,typescript,javascript)