我已经四处寻找解决这个问题的办法了。他们都建议在你的tsconfig中添加"jsx": "react"。json文件。我已经做到了。另一个是添加“include:[]”,我也这样做过。然而,当我试图编辑.tsxfiles时,我仍然得到错误。下面是我的tsconfig文件。

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "allowJs": true,
        "checkJs": false,
        "jsx": "react",
        "outDir": "./build",
        "rootDir": "./lib",
        "removeComments": true,
        "noEmit": true,
        "pretty": true,
        "skipLibCheck": true,
        "strict": true,
        "moduleResolution": "node",
        "esModuleInterop": true
    },
    "include": [
        "./lib/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}

任何建议都会很有帮助。我使用babel 7编译所有的代码与env, react和typescript预设。如果你们需要更多的文件来帮助调试,请告诉我。


当前回答

崇高文本的解决方案:

Make sure your package.json uses Typescript >= v4.1.2 Uninstall the Sublime Text "Typescript" package through Package Control At time of writing, it bundles Typescript v3.x Open a terminal in the Sublime Text "Packages" directory. cd "~/Library/Application Support/Sublime Text 3/Packages" Clone the Typescript-Sublime-Plugin repo into your Packages directory: git clone https://github.com/microsoft/TypeScript-Sublime-Plugin TypeScript Open User Settings: Sublime Text > Preferences > Settings Add "typescript_tsdk": "node_modules/typescript/lib" This tells the Sublime Typescript plugin to use the project version of Typescript rather than its bundled version. Restart Sublime Text Unlike most Sublime Text settings, this one requires a restart in order to restart the Typescript server.

参考: https://github.com/microsoft/TypeScript-Sublime-Plugin/issues/538

其他回答

崇高文本的解决方案:

Make sure your package.json uses Typescript >= v4.1.2 Uninstall the Sublime Text "Typescript" package through Package Control At time of writing, it bundles Typescript v3.x Open a terminal in the Sublime Text "Packages" directory. cd "~/Library/Application Support/Sublime Text 3/Packages" Clone the Typescript-Sublime-Plugin repo into your Packages directory: git clone https://github.com/microsoft/TypeScript-Sublime-Plugin TypeScript Open User Settings: Sublime Text > Preferences > Settings Add "typescript_tsdk": "node_modules/typescript/lib" This tells the Sublime Typescript plugin to use the project version of Typescript rather than its bundled version. Restart Sublime Text Unlike most Sublime Text settings, this one requires a restart in order to restart the Typescript server.

参考: https://github.com/microsoft/TypeScript-Sublime-Plugin/issues/538

在我的情况下,我尝试了所有的tsconfig。json,项目属性对话框,重新启动IDE,检查安装的TypeScript版本等,它仍然有这个错误。找到开发人员,使项目添加条件属性的项目文件,这样TypeScriptJSXEmit没有定义在所有的配置(这混淆了项目属性对话框)。

这是从我的项目文件显示的问题摘录:

...
  <PropertyGroup Condition="'$(Configuration)' == 'QA'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptJSXEmit>React</TypeScriptJSXEmit>
...

重新启动IDE似乎太残酷了,而且并不总是有效。你想要重新启动TS服务器:

注意:该选项只会显示当你的IDE有任何TS相关文件打开

添加 { " compilerOptions ": { “jsx”:“反应” } } “tsconfig。重新启动编辑器就解决了这个问题。

如果你在运行create-react-app with Typescript后看到这个问题,你可以通过添加“Typescript . bat”来解决这个问题。Tsdk ": "node_modules/typescript/lib"到.vscode/settings.json。

对于智能感知,如果你使用"jsx": "react-jsx",你需要切换你的工作空间来使用TS 4.1+

或者从视觉上看,只需转到蓝色任务栏并选择Typescript版本(可能是4.x。x something),然后选择“select TypeScript Version”。

然后选择“Use Workspace Version Version”,引用node_modules/typescript/lib