-
Why does |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@Jazzmanpw You answered your own question, I believe 😄
Hooks can be called from anywhere, and the library can't be smart enough to know for sure that your params will be defined. We chose to optimize for real type safety here, and that means acknowledging that a parameter might be undefined.
Not exactly. If you are certain your parameter will be defined, you can use type casting or the non-null assertion operator to avoid a runtime check. let { param } = useParams() as { param: "definitely defined" }
// or
let { param } = useParams<{ param: "definitely defined" }>();
let str = param!.toLowerCase(); |
Beta Was this translation helpful? Give feedback.
@Jazzmanpw You answered your own question, I believe 😄
Hooks can be called from anywhere, and the library can't be smart enough to know for sure that your params will be defined. We chose to optimize for real type safety here, and that means acknowledging that a parameter might be undefined.
Not exactly. If you are certain your parameter will be defined, you can use type casting or the non-null assertion operator to avoid a runtime check.