Reactjs 用typescript响应路由器

Reactjs 用typescript响应路由器,reactjs,typescript,react-router,react-router-dom,Reactjs,Typescript,React Router,React Router Dom,我正在使用带有Typescript的react-router和react-router-dom来构建一个应用程序。我以这种方式定义了我的路线(routes.tsx): 编译器抛出此错误 (5,4): Type '{}' is not assignable to type 'Readonly<RouterProps>'. Property 'history' is missing in type '{}'. (5,4):类型“{}”不可分配给类型“Readonly”。 类型“{}

我正在使用带有Typescript的
react-router
react-router-dom
来构建一个应用程序。我以这种方式定义了我的路线(
routes.tsx
):

编译器抛出此错误

(5,4): Type '{}' is not assignable to type 'Readonly<RouterProps>'.
  Property 'history' is missing in type '{}'.
(5,4):类型“{}”不可分配给类型“Readonly”。
类型“{}”中缺少属性“history”。

我是TS新手,所以我不确定到底发生了什么。

TypeScript与大多数语言一样,在类的
标记之间需要一个类型说明符。这表明该类是一个需要进一步定义的泛型

我找不到您正在使用的关于这个类的特定文档,但我想这样的东西可能会帮助您找到正确的位置:

const App: React.StatelessComponent<RouterProps> = () => (
  <Routes />
);
const-App:React.StatelessComponent=()=>(
);

这很接近,但它说
RouterProps
不是通用的应该是
导出默认路由
(5,4): Type '{}' is not assignable to type 'Readonly<RouterProps>'.
  Property 'history' is missing in type '{}'.
const App: React.StatelessComponent<RouterProps> = () => (
  <Routes />
);