我正在使用从和导入类型的@types/react-router-dom版本4.3.1中的类型。@types/react-router@types/history
在我的应用程序中,我总是有两个处于位置状态的属性,我希望它们可以自动从RouteComponentProps界面中拉出,而不必LocationState每次都将自定义类型变量传递给界面。
RouteComponentProps接口的定义react-router如下:
import * as H from 'history';
export interface RouteComponentProps<Params extends { [K in keyof Params]?: string } = {}, C extends StaticContext = StaticContext, S = H.LocationState> {
history: H.History;
location: H.Location<S>;
match: match<Params>;
staticContext?: C;
}
Run Code Online (Sandbox Code Playgroud)
引用的接口/类型的定义history是:
export interface Location<S = LocationState> {
pathname: Pathname;
search: Search;
state: S;
hash: Hash;
key?: LocationKey;
}
export type LocationState = History.LocationState;
export namespace …Run Code Online (Sandbox Code Playgroud)