reactjs - TS2709:不能使用命名空间“InspectOptions”作为类型
问题描述
我目前正在编译一个打字稿文件,其中包含以下内容index.ts
export { default as Button } from './component/Button';
export type { Icon } from './component/Button';
我目前正在导出声明,Icon
因为我将在另一个文件中重用它。
通过 lerna 命令编译它时lerna run build
,我得到了这个:
../../node_modules/@types/node/console.d.ts:35:37 - error TS2709: Cannot use namespace 'InspectOptions' as a type.
35 dir(obj: any, options?: InspectOptions): void;
~~~~~~~~~~~~~~
../../node_modules/@types/node/repl.d.ts:101:43 - error TS2709: Cannot use namespace 'InspectOptions' as a type.
101 const writer: REPLWriter & { options: InspectOptions };
~~~~~~~~~~~~~~
当我尝试通过 编译它时tsc --project ./tsconfig.build.json
,我得到了这个:
src/index.ts:2:1 - error TS1128: Declaration or statement expected.
2 export type { Icon } from './component/Button';
~~~~~~
src/index.ts:2:13 - error TS1005: ';' expected.
2 export type { Icon } from './component/Button';
~
src/index.ts:2:27 - error TS1005: ';' expected.
2 export type { Icon } from './component/Button';
如下tsconfig.build.json
:
{
"compilerOptions": {
"module": "esnext",
"target": "es5",
"outDir": "./dist",
"jsx": "react",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": false,
"sourceMap": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"declaration": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist"
],
}
我还在 github 上看到了这篇文章:https ://github.com/Microsoft/TypeScript/issues/27311但不确定如何应用提到的解决方案或是否适用于上述问题。
任何想法?
解决方案
我已经通过运行解决了上述问题npm install -g typescript@latest
。
如果您想查看系统上安装的当前 typescript 版本,请运行tsc -v
感谢 Aluan 指出这一点。
如果在 typescript 更新后仍然遇到这个问题,可以考虑"skipLibCheck": true,
在tsconfig.json
推荐阅读
- tfs - 有没有办法从 TFS 构建生成 Intellitrace 文件?
- node.js - Tizen 和 Ubuntu 的兼容性
- bash - 如何循环 CURL 命令?
- python - 如何将对象与字符串进行比较?
- react-native - 如何有条件地渲染输入附件视图?
- node.js - 将数据从节点传递到 React
- fonts - jsPDF中ZaptDingBats和Symbols的映射是什么?
- python - 如何将零添加到一位数(时间)?
- c# - C# VS 2019 SQLException:代码适用于控制台应用程序,但不适用于 WebForms 应用程序
- python-3.x - 无法使用本地文件夹中的模块