Next.js Discord

Discord Forum

How to preserve type safety of props in a custom hook which wrap a library hook?

Unanswered
Argente Brun posted this in #help-forum
Open in Discord
Argente BrunOP
How can I define proper types for the control and fieldsToTrack arguments in the useWatchFields hook to resolve these type errors and improve type safety?
Are there any recommended practices for defining types for custom hooks?

Relevant file path: src/app/use_watch_hook_issue/page.tsx
Repo link: https://github.com/samiUllah1526/ts_questions

3 Replies

Arboreal ant
That file is empty
https://github.com/samiUllah1526/ts_questions/commit/0c491525e6335ae90d748877a4e1e9c08c2b1c19

The typescript discord is normally a pretty good place to go for typescript specific questions. This isn't really related to next. You're more likely to get a good answer there I reckon.

But you should check the types of the inputs and outputs of the lib you want to wrap, then just annotate the inputs and outputs of your custom hook with those.
Arboreal ant
Weird. This is all I see: