最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vue.js - Can I declare the 'globalThis' property with TypeScript in two Vue files without polluting each other?

programmeradmin8浏览0评论

In my code, TypeScript is only used to provide type hints for developers, without participating in the compilation checks.

Maybe using window is simpler, but I prefer globalThis.

To avoid them polluting each other's globalThis.I want to know if it's possible to do this.

I want to attach types to globalThis, but the scope should be limited to a single file only.

File1.vue

<script setup lang="ts">
declare global {
    var arrayOne: string[]
    var arrayTwo: string[]
}

// globalThis.arrayThree   X any type ts-plugin(7017)
</script>

<template>
</template>

File2.vue

<script setup lang="ts">
declare global {
    var arrayOne: number[]
    var arrayThree: number[]
}

// globalThis.arrayTwo   X any type ts-plugin(7017)
</script>

<template>
</template>
发布评论

评论列表(0)

  1. 暂无评论