我有一个像这样的简单 vuex 状态。我的目标是最初将 currentScreen
属性设置为 screenList
...
state: {
screenList:[{...},{...}], // typed as Array<Screen>
currentScreen: this.screenList[0] //typed as Screen
}
但是 typescript 编译器遇到以下错误:
Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
据我所知,这是因为 this
的上下文可能会根据它的调用位置而变化,因此 screenList
没有明确输入。
如何通过以兼容打字稿的方式引用状态 currentScreen
属性来设置 screenList
?