Skip to content

Commit c339133

Browse files
sandersndanielrearden
authored andcommitted
🤖 Merge PR DefinitelyTyped#45780 Fix react-router hooks test by @sandersn
microsoft/TypeScript#39081, which ships in Typescript 4.0, stops using binding patterns as contextual types for return type inference. react-router's `useParams` relied on this to fill in an object with `any`s in case a binding pattern was used but no type argument was provided. This no longer works. This fix just adds a type argument to the tests. For two other, more complete fixes, see microsoft/TypeScript#39081 (comment) Briefly, the options are (1) go back to returning `any`-filled object types or (2) tries to default to `string`. The second fix is probably the right one, but it may hurt compilation/IDE performance, so I'll leave it to the package owners to decide whether to make that change.
1 parent 17eb1cb commit c339133

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

types/react-router/test/hooks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface LocationState {
2121
const HooksTest: React.FC = () => {
2222
const history = useHistory<LocationState>();
2323
const location = useLocation<LocationState>();
24-
const { id } = useParams();
24+
const { id } = useParams<Params>();
2525
const params = useParams<Params>();
2626
// $ExpectType OptionalParams
2727
const optionalParams = useParams<OptionalParams>();

0 commit comments

Comments
 (0)