Mobx无法解析可观察属性decorator



我想创建一个数据类型为map的mobx-observable。这就是我装饰地图的方式:

@observable.map items: Map<number, Item> = new Map();

当我这样做时,我会收到以下错误消息:

the return type of a property decorator function must be either 'void' or 'any'. 
unable to resolve signature of property decorator when called as an expression.

是什么原因导致了错误?

这是我的tsconfig.json文件:

{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist/",
"baseUrl": "./src",
"paths": {
"@lib/*": ["../../lib/src/*"], // relative to baseUrl
},
"lib": [ "dom" ],
"jsx": "react",
"esModuleInterop": true,
},
"types": [
"babylonjs",
"jest",
],
"typeRoots": [
"./node_modules/@types"
],
"plugins": [
{
"name": "typescript-plugin-css-modules"
}
]
}

我从未使用过observable.map作为注释/装饰器,所以如果问题是由装饰器配置引起的,请在此处更正。

以下可能是的一个很好的替代方案

@observable.ref items: ObservableMap<number, Item> = observable.map();

通过这种方式,您可以跟踪项目的重新分配,但也将跟踪映射中的所有值。

注意:mobx导出ObservableMap类型/类。

最新更新