非常简单的项目,仅使用命令行就没有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"
}
下决心
解决了我的问题。在本地安装了类型记录,但运行的是全局安装和旧版本的类型记录。当我通过npm脚本运行tsc时,它使用以下命令进行编译:
tsc --jsx react --target es6 --module commonjs src/lib/Fetch.tsx
发布于 2018-06-06 13:03:56
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
https://stackoverflow.com/questions/50721103
复制相似问题