'Mobx cannot resolve observable property decorator
I want to create a mobx observable whose data type is map. This is how I'm decorating the map:
@observable.map items: Map<number, Item> = new Map();
When I do this, I'm getting this error message:
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.
What could be causing the error?
Here's my tsconfig.json file:
{
"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"
}
]
}
Solution 1:[1]
I've never used observable.map as an annotation/decorator, so please correct me here if the issue was due to decorator configs.
The following could be a good alternative though
@observable.ref items: ObservableMap<number, Item> = observable.map();
This way you can track re-assignments on items, but all the values inside the map will also be tracked.
Note: mobx exports the ObservableMap type/class.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | cipher |
