我正在使用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
,则那里不存在任何错误,但我想使用第一种方法。