在我的应用中添加按钮时。显示此类错误时,我无法理解。
/media/XXPath1/XXPath2/React-Wrokspace/resto/node_modules/react-bootstrap/esm/index.d.ts(2,1)中的TypeScript错误: 需要声明或声明。 TS1128
1 | export { default as Accordion } from './Accordion';
> 2 | export type { AccordionProps } from './Accordion';
| ^
3 | export { default as AccordionContext } from './AccordionContext';
4 | export { default as AccordionCollapse } from './AccordionCollapse';
5 | export type { AccordionCollapseProps } from './AccordionCollapse';
代码:
import React, { Component } from 'react';
import { Button } from 'react-bootstrap';
class RestaurantList extends Component {
render() {
return (
<div>
<h1>RestaurantList</h1>
<Button variant="primary">Submit</Button>
</div>
);
}
}
export default RestaurantList;
Package.json
{
"name": "resto",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"@types/jest": "^24.9.1",
"@types/node": "^12.19.0",
"@types/react": "^16.9.53",
"@types/react-bootstrap": "^0.32.24",
"@types/react-dom": "^16.9.8",
"@types/react-router-dom": "^5.1.6",
"axios": "^0.20.0",
"bootstrap": "^4.5.3",
"json-server": "^0.16.2",
"react": "^17.0.1",
"react-bootstrap": "^1.3.0",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.4",
"reactstrap": "^8.6.0",
"typescript": "^3.7.5"
},
}
答案 0 :(得分:0)
我挣扎了一分钟,想知道到底发生了什么,直到我检查了package.json文件,并看到尽管编辑器正在使用3.7.5
,但该版本仅为3.9.X
。升级版本解决了该问题。
试试这个npm install -g typescript@latest
。您也可以在没有最新修饰符的情况下使用此命令npm update
代替安装。