-
import { useParams } from 'wouter';
export default function Hello() {
const params = useParams(); // eslint report `Unsafe assignment of an `any` value.`
return (
<div>
<h1>Hello, {params.name}</Heading>
</div>
);
} How to correctly type the params variable? I tried adding generic type variables but it didn't work. |
Beta Was this translation helpful? Give feedback.
Answered by
molefrog
Oct 17, 2023
Replies: 1 comment 3 replies
-
useParams can’t automatically infer the type of parameters used, so it returns any by default. So you need to cast it manually, or provide a generic argument: Also, the types were broken for TS4.1 as shown here #360 |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
molefrog
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
useParams can’t automatically infer the type of parameters used, so it returns any by default. So you need to cast it manually, or provide a generic argument:
useParams<{ id: string }>()
. Does that work?Also, the types were broken for TS4.1 as shown here #360