In Vue2 + Typescript
我有的项目global.d.ts
具有某些类型的文件,例如:
全局.d.ts
type Nullable<T> = T | undefined | null;
在常规中使用时它工作正常(无需明确类型导出/导入).ts
files:
misc.ts
const answer: Nullable<Answer> = null;
但里面不起作用.vue
files:
组件.vue
<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
data: () => ({
answer: null as Nullable<Answer> // 'Nullable' is not defined
})
});
</script>
三斜杠也不起作用:
<script lang="ts">
/// <reference path="../../types/global.d.ts" />
import Vue from 'vue';
export default Vue.extend({
data: () => ({
answer: null as Nullable<Answer> // 'Nullable' is not defined
})
});
</script>
有什么解决办法吗?
我通过添加目录路径来解决这个问题global.d.ts
文件输入tsconfig.json
:
{
"compilerOptions": {
"typeRoots": [
"./types"
]
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)