我已经四处寻找解决这个问题的办法了。他们都建议在你的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

其他回答

你可以创建一个。vscode/settings。Json文件在你的项目的根。在里面输入{"typescript。Tsdk ": "node_modules\\typescript\\lib"}你就可以开始了。

问题是vscode使用的是旧的Typescript版本。

在vscode上显示代码的图像

我得到了同样的错误,我只是想办法解决它。问题是有一个jsconfig。tsconfig. json文件导致TypeScript编译器忽略tsconfig. json文件。json文件。

要确定你是否有同样的问题,在你的IDE中(我使用VS Code),在你的编辑器中加载一个有错误的文件,然后打开命令面板,输入“TypeScript: Go To Project Configuration”。如果它打开jsconfig。json,然后删除该文件并重新启动IDE。如果它打开tsconfig。Json文件这次,你是黄金。

为了解决未来所有项目的这个问题,你可以为VSCode安装JavaScript和TypeScript Nightly扩展。

对于使用Visual Studio 2019的人,您可以通过执行以下所有操作来修复它:

在tsconfig。Json,有这部分

"include": [
    "./src/**/*.ts"
]

更新C:\Program Files (x86)\Microsoft SDKs\ Typescript中的Typescript sdk 我有4.0版本。我需要将它更新到4.1(更清楚地说,是4.1.2) 删除Typescript文件夹 在Visual Studio 2019 Extensions > Manage Extensions中,安装Typescript 4.1 for Visual Studio

崇高文本的解决方案:

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