khi*_*erl 13 typescript reactjs create-react-app
这是 cra 的全新安装,在节点 13.11.0 上运行打字稿模板,尝试运行 npm start 时出现错误
TypeScript error in D:/Projects/personal-site/node_modules/@types/testing-library__react/node_modules/pretty-format/build/index.d.ts(7,13):
'=' expected. TS1005
5 | * LICENSE file in the root directory of this source tree.
6 | */
> 7 | import type * as PrettyFormat from './types';
| ^
8 | /**
9 | * Returns a presentation string of your `val` object
10 | * @param val any potential JavaScript object```
Run Code Online (Sandbox Code Playgroud)
kei*_*kai 16
感谢marcelo-waisman的帖子。
如果我们严格按照文档...
yarn add typescript @types/node @types/react @types/react-dom @types/jest
Run Code Online (Sandbox Code Playgroud)
...我们应该安装最新版本的 TypeScript,而不是可能仍低于 3.8.0 的本地-全局版本。
我找到了一些线索。也许值得开一个问题。
它与包pretty-format
及其类型有关create-react-app
。我们可以在这里找到源代码:pretty-format/src/index.ts
import style = require('ansi-styles');
import type * as PrettyFormat from './types';
Run Code Online (Sandbox Code Playgroud)
从提交历史中,我们可以看到前两天有一个相关的Pull Request,将这部分从...
import * as PrettyFormat from './types';
Run Code Online (Sandbox Code Playgroud)
... 到...
import type * as PrettyFormat from './types';
Run Code Online (Sandbox Code Playgroud)
这似乎是错误的原因。
实际上,这种“导入类型”是 Typescript 3.8 https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-exports 中引入的新语法
解决方案实际上非常简单(如果它是您的选择),只需将您的打字稿升级到 3.8+
归档时间: |
|
查看次数: |
5101 次 |
最近记录: |