Typescript 错误TS2318:找不到全局类型';对象';

Typescript 错误TS2318:找不到全局类型';对象';,typescript,typescript-typings,Typescript,Typescript Typings,非常简单的项目,没有tsconfig.json,只需使用命令行即可: tsc --jsx react --target es6 --lib dom src/lib/Fetch.tsx 我得到了以下错误,我不明白为什么,这些类型在每个地方都有定义,特别是在lib.es6.d.ts中,我相信它包含在--target es6 error TS2318: Cannot find global type 'Array'. error TS2318: Cannot find global type 'Bo

非常简单的项目,没有tsconfig.json,只需使用命令行即可:

tsc --jsx react --target es6 --lib dom src/lib/Fetch.tsx
我得到了以下错误,我不明白为什么,这些类型在每个地方都有定义,特别是在lib.es6.d.ts中,我相信它包含在
--target es6

error TS2318: Cannot find global type 'Array'.
error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'Function'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'Number'.
error TS2318: Cannot find global type 'Object'.
error TS2318: Cannot find global type 'RegExp'.
是否安装了以下依赖项

"dependencies": {
  "@types/react-dom": "^16.0.6",
  "@types/react": "^16.3.16",
  "react": "^16.4.0",
  "react-dom": "^16.4.0"
},
"devDependencies": {
  "@types/node": "^10.3.1",
  "typescript": "^2.9.1"
}
决心

解决了我的问题。在本地安装了typescript,但正在运行全局安装的旧版本typescript。当我通过npm脚本运行tsc时,它使用以下命令编译:

tsc --jsx react --target es6 --module commonjs src/lib/Fetch.tsx

dom
只包含特定于浏览器的dom元素的定义。您需要包括一个
es*
库,其中包括编译所需的核心es类型。指定
--lib
选项后,必须包含所有必要的类型,编译器将不再包含任何基于目标的库:

tsc --jsx react --target es6 --lib es2015,dom src/lib/Fetch.tsx
或者,如果您实际上不只是使用默认库,则可以完全忽略该选项:

tsc --jsx react --target es6 src/lib/Fetch.tsx

不幸的是,这两种方法都不起作用。他们都抱怨AbortController、csstype(在@types/react/index.d.ts中)以及RequestInt和signal。我构建了一个更独立的示例,将用细节更新我的问题。@AustinFrance尝试使用更高版本的es库es2018。但是这些内置类型找不到的具体错误是由于缺少默认的es库造成的。当我在本地安装了较新版本时,我正在运行全局安装的较旧版本的typescript。如果我通过npm运行tsc,我的原始代码运行得很好,不过我还必须包括--module commonjs以防止@types/react抱怨。将您的标记为答案,因为仅给出问题的上下文,添加--lib dom确实会产生所看到的错误,删除--lib dom会纠正这一点,正如您所建议的。