vue-typescript-starter icon indicating copy to clipboard operation
vue-typescript-starter copied to clipboard

引入elementUi的部分

Open webtianjia opened this issue 6 years ago • 8 comments

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

webtianjia avatar Nov 20 '18 10:11 webtianjia

same issue..

Debiancc avatar Nov 20 '18 17:11 Debiancc

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

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

Debiancc avatar Nov 21 '18 01:11 Debiancc

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 avatar Nov 21 '18 01:11 webtianjia

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

webtianjia avatar Nov 21 '18 02:11 webtianjia

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

ws456999 avatar Nov 21 '18 05:11 ws456999

@Debiancc @webtianjia

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

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

ws456999 avatar Nov 21 '18 05:11 ws456999

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

webtianjia avatar Nov 21 '18 06:11 webtianjia

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

Debiancc avatar Nov 22 '18 02:11 Debiancc