【问题标题】:VSCode not picking up jsx when tsconfig is extended扩展 tsconfig 时 VSCode 不拾取 jsx
【发布时间】:2019-06-12 19:40:12
【问题描述】:

我有一个按以下方式构建的 monorepo 项目

/web
/native
  /tsconfig.json
tsconfig.json

我的/native/tsconfig.json 看起来像这样

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "jsx": "react-native"
  }
}

但由于某种原因,我的 .tsx 带有一些 jsx 的文件返回以下错误

[ts] 除非提供了“--jsx”标志,否则无法使用 JSX。 [17004]

当我使用 cli tsc 进行类型检查时,我没有收到这些错误。

【问题讨论】:

    标签: reactjs typescript visual-studio-code jsx


    【解决方案1】:

    您需要在tsconfig 中指定这样的文件夹。

    "include": [
      "./src/ts/**/*" //Path to your source
    ],
    "jsx": "preserve",
    

    【讨论】:

      【解决方案2】:

      VsCode 工作区和 package.json 中的 Typescript 版本不相等。 为了在 Vscode 中解决这个问题,

      1. 打开 tsx 文件。在右下角你会发现

      2 单击此按钮并选择更改 VS Code 以使用工作区的 Typescript 版本。

      错误会消失。

      【讨论】:

        猜你喜欢
        • 2018-04-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-30
        • 2016-02-25
        • 2020-04-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多