🤖 Merge PR #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

https://github.com/microsoft/TypeScript/pull/39081#issuecomment-644393729

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.
This commit is contained in:
Nathan Shively-Sanders 2020-06-29 13:41:10 -07:00 committed by GitHub
parent 42b597fab0
commit cbbbfecf45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,7 @@ interface LocationState {
const HooksTest: React.FC = () => {
const history = useHistory<LocationState>();
const location = useLocation<LocationState>();
const { id } = useParams();
const { id } = useParams<Params>();
const params = useParams<Params>();
// $ExpectType OptionalParams
const optionalParams = useParams<OptionalParams>();