reactjs - TypeScript 中缺少属性
问题描述
class RolloutStoreClass {
import { observable, action, makeAutoObservable } from "mobx";
public queue = observable<IDeploymentProject>([]);
public inProcess = observable<IDeploymentProject>([]);
public successfull = observable<IDeploymentProject>([]);
public failed = observable<IDeploymentProject>([]);
constructor() {
makeAutoObservable(this);
}
@action
private clearQueue(): void {
this.queue = [] ;
this.inProcess = [];
this.failed = [];
this.successfull = [];
}
}
export const RolloutStore = new RolloutStoreClass();
我在 clearQueue 函数上得到了这个问题。队列
错误是:
在“never []”类型中,缺少“Observable Array”类型的以下属性:“spliceWithArray, clear, replace, remove, toJSON”。
解决方案
您要么需要使您的queue
(和其他字段)常规数组,所有可观察性仍然有效。
或者使用.clear()
里面的方法clearQueue
:
private clearQueue(): void {
this.queue.clear();
// ...
}
还有一件事:当你使用时,makeAutoObservable
你不需要显式标记action
'sobservable
等等,你可以删除所有的装饰器:
class Foo {
// Don't need explicit observable decorator
public queue: IDeploymentProject[] = [];
// ...
constructor() {
makeAutoObservable(this);
}
// You can remove action decorator
private clearQueue(): void {
this.queue = [] ;
this.inProcess = [];
this.failed = [];
this.successfull = [];
}
}
推荐阅读
- rust - 如何在 Rust 中向上或向下舍入一个数字?
- ios - StackView(ios)中的视图未添加底部边框
- python - gzip -t 循环运行脚本
- javascript - 用对象反应状态
- c - 为 c 中的 char 分配负值打印“?” 在 macOS 上
- php - 在 CentOS Linux 上以二进制模式写入的疯狂 PHP fopen / fwrite / file_put_contents / move_uploaded_file 错误将 0x0D 添加到每个 0x0A
- python - 了解嵌套装饰器缺少所需的位置参数错误
- c# - 动态换出或切换控件的可见性
- javascript - React-无法使用容器组件中定义的功能从子组件更改状态
- cassandra - 了解 Cassandra 池选项(setCoreConnectionsPerHost 和 setMaxConnectionsPerHost)?