ws456999 / vue-typescript-starter

vue-typescript-starter 脚手架
327 stars 95 forks source link

引入elementUi的部分 #14

Open webtianjia opened 5 years ago

webtianjia commented 5 years ago

我在main.ts 引入了elementUi,使用时却找不到他的方法

Debiancc commented 5 years ago

same issue..

Debiancc commented 5 years ago
declare global {
  namespace JSX {
    interface Element extends VNode{
      // 'el-form': ElForm
    }
    interface ElementClass extends Vue {}
    interface IntrinsicElements{
      [elem: string]: any;
    }
  }
}

我尝试使用tsx来写Vue,ts静态检查找不到elementUI可以使用上面这种方式来声明

webtianjia commented 5 years ago
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;
    }
  }
}

在src 目录下 shims-tsx.d.ts 但是它并没有生效

webtianjia commented 5 years ago

56:14 Property '$Message' does not exist on type 'HelloWorld'.
    54 |
    55 |         public greet(i: any) {
  > 56 |             this.$Message("hello")
       |              ^
    57 |         }
    58 |     }
    59 |```
ws456999 commented 5 years ago

@webtianjia 请问有最小重现的repo么

ws456999 commented 5 years ago

@Debiancc @webtianjia

declare module 'vue/types/vue' {
  interface Vue {
    $Message: any,
    $Modal: any
  }
}

这段代码加到d.ts里面了么

webtianjia commented 5 years ago

@Debiancc 已经可以了 ,我安装了 "vue-cli-plugin-element": "^1.0.0", 我使用了vue-cli3

Debiancc commented 5 years ago

@ws456999 这种workaround只是骗过tsc的静态检查,有什么办法可以让element-ui的types直接委托过来吗