Как использовать пространство имен, определенное в 'd.ts' в '.vue'? - PullRequest
0 голосов
/ 19 февраля 2019

Я использую 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, то там не будет никаких ошибок, но я хочу использовать первый способ.

...