-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
help wantedExtra attention is neededExtra attention is needed
Description
import { type Lens, useLens } from '@hookform/lenses'
import { zodResolver } from '@hookform/resolvers/zod'
import { useForm } from 'react-hook-form'
import { z } from 'zod'
const EmailAddressS = z.string().min(1).email().brand('EmailAddress')
type EmailAddress = z.infer<typeof EmailAddressS>
const FormSchema = z.object({ email: EmailAddressS })
type FormValue = z.infer<typeof FormSchema>
const Child = ({ lens }: { lens: Lens<FormValue> }) => <></>
function Parent() {
const { control } = useForm({ resolver: zodResolver(FormSchema) })
const lens = useLens({ control })
/*
Here cannot pass lens as type info is reduced to plain string in useLens().
Probably "brand" should be opaque/unchecked.
....
Types of property 'email' are incompatible.
Type 'string | undefined' is not comparable to type 'string & BRAND<"EmailAddress">'.
Type 'string' is not comparable to type 'string & BRAND<"EmailAddress">'.
Type 'string' is not comparable to type 'BRAND<"EmailAddress">'.
*/
return <Child lens={lens} />
}
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed