Skip to content

Commit

Permalink
[typescript] Result of hoc withRouter should not require props provid…
Browse files Browse the repository at this point in the history
…ed by it (#223)
  • Loading branch information
rosskevin authored and taion committed Jan 1, 2019
1 parent 1ee0886 commit 6a96faa
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 24 deletions.
9 changes: 0 additions & 9 deletions test/typescript/MainPage.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions test/typescript/WidgetsPage.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ function AppPage({ children }: { children: React.ReactNode }) {
);
}

export default AppPage;
export { AppPage };
9 changes: 9 additions & 0 deletions types/example-app/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as React from 'react';
import { WithRouterComponent } from './WithRouterComponent';

const MainPage = () => (
<div>
<WithRouterComponent />
</div>
);
export { MainPage };
4 changes: 4 additions & 0 deletions types/example-app/WidgetsPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as React from 'react';

const WidgetsPage = () => <div />;
export { WidgetsPage };
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export interface MyProps {
foo?: boolean;
}

export default withRouter(
const WithRouterComponent = withRouter(
class MyRoutedComponent extends React.Component<MyProps & WithRouter> {
public render() {
render() {
const {
match: { location },
router,
Expand All @@ -20,3 +20,5 @@ export default withRouter(
}
},
);

export { WithRouterComponent };
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
Redirect,
Route,
} from 'found';
import WidgetsPage from './WidgetsPage';
import AppPage from './AppPage';
import MainPage from './MainPage';
import { WidgetsPage } from './WidgetsPage';
import { AppPage } from './AppPage';
import { MainPage } from './MainPage';

const fetchWidget = (widgetId: any) =>
new Promise(resolve => {
Expand All @@ -32,7 +32,7 @@ const BrowserRouter = createBrowserRouter({
<Route
path="widgets/:widgetId"
getComponent={() =>
import('./WidgetsPage').then(module => module.default)
import('./WidgetsPage').then(module => module.WidgetsPage)
}
getData={({ params: { widgetId } }) =>
fetchWidget(widgetId).catch(() => {
Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ declare module 'found' {
router: Router;
}

function withRouter<OriginalProps>(
Component: React.ComponentType<OriginalProps & WithRouter>,
): React.ComponentType<OriginalProps>;
function withRouter<Props extends WithRouter>(
Component: React.ComponentType<Props>,
): React.ComponentType<Omit<Props, keyof WithRouter>>;

class RedirectException {
constructor(location: string | LocationDescriptor);
Expand Down
2 changes: 1 addition & 1 deletion types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"typeRoots": ["../"],
"types": []
},
"include": ["./*.ts", "./*.tsx"]
"include": ["./**/*.ts", "./**/*.tsx"]
}

0 comments on commit 6a96faa

Please sign in to comment.