首页 > 解决方案 > 如何在codesandbox中为react+typescript+mobx添加装饰器支持?

问题描述

我希望能够在代码沙箱中的@observer打字稿代码中使用 mobx。但是我收到此错误:

/src/content.tsx:目前未启用对实验性语法“decorators-legacy”的支持 (6:1):

  4 | import { observer } from "mobx-react";
  5 | 
> 6 | @observer
    | ^
  7 | export class Particle extends React.Component {

我已经:

1) 添加依赖项

在此处输入图像描述

2)添加.babelrc包含这些内容的文件

在此处输入图像描述

但我无法摆脱错误。我该如何解决?

标签: codesandbox

解决方案


File > Preference > Settings > Search "experimental"

然后检查Javascript › Implicit Project Config: Experimental Decorators


推荐阅读