Skip to content

TypeScript: What type for register (instead of any) when calling it as a prop? #4426

Answered by ritikbanger
ptmkenny asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @ptmkenny, if you are calling register as a prop in a custom component or in some custom form field in Typescript, then you can use the below code.

First of all import the UseFormRegister and FieldValues from 'react-hook-form'

import {UseFormRegister, FieldValues } from 'react-hook-form'

After that, define the type of register as

register: UseFormRegister<FieldValues>

and boom, you don't need to use 'any' type for register.

Replies: 7 comments 21 replies

Comment options

You must be logged in to vote
2 replies
@whompyjaw
Comment options

@whompyjaw
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@jmayergit
Comment options

@ptmkenny
Comment options

@Kevin-Carlos
Comment options

@ptmkenny
Comment options

@Kevin-Carlos
Comment options

Comment options

You must be logged in to vote
13 replies
@andreynav
Comment options

@techdan-to
Comment options

@ritikbanger
Comment options

@IanVS
Comment options

@Henry-GLS-NXT
Comment options

Answer selected by ptmkenny
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@omeryaz
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet