我不明白为什么它找不到它。
$ cat tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"target": "es6",
"jsx": "react",
"types": [
"lodash",
"react",
"react-dom"
]
}
}
$ tree node_modules/@types
node_modules/@types/
├── lodash
│ ├── README.md
│ ├── index.d.ts
│ ├── package.json
│ └── types-metadata.json
├── react
│ ├── README.md
│ ├── index.d.ts
│ ├── package.json
│ └── types-metadata.json
└── react-dom
├── README.md
├── index.d.ts
├── package.json
├── server.d.ts
└── types-metadata.json
在组件文件中导入。
// src/components/component.tsx
import * as React from "react";
是什么赋予了?
原文由 AJcodez 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果你不使用 typescript 2.1,你应该升级到它。看起来您使用的是来自 @types 的 2.x 版本。
这是我现在正在使用的工作
tsconfig.json
文件:自从我解决了您遇到的相同问题以来已经有几天了,但我认为这里的关键是
"moduleResolution": "node"
和"allowJs": true
。