如何使用在'.vue'中的'd.ts'定义的命名空间?

时间:2019-02-19 10:56:43

标签: vue.js vuejs2 namespaces typescript-typings typescript3.0

我正在使用Vue.js 2和TypeScript 3.3,在定义名称空间时遇到问题。

// src/components/my-component.vue

<template>
...
</template>

<script lang="ts">
import { Vue, Component } from "vue-property-decorator";

@Component()
export default class MyComponent extends Vue {
    private foo: MyComponent.MyEnumType;
//               ^^^^^^^^^^^
//               'MyComponent' only refers to a type, but is being used as a namespace here.
    constructor() { super(); }
}
</script>
// src/types/components/my-component.d.ts

declare namespace MyComponent {
    type MyEnumType = "foo" | "bar";
}
{
    ...
    "typeRoots": ["node_modules/@types", "src/types"]
    ...
}

'MyComponent' only refers to a type, but is being used as a namespace here. 我不明白为什么会发生此问题。 如果我将TypeScript的一部分分隔为.ts,则那里不存在任何错误,但我想使用第一种方法。

0 个答案:

没有答案
相关问题