Checked branded types
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- frontend
Research direction
Start with the useLens type definitions and reproduce the issue using the branded EmailAddress and FormSchema shown in the report. Trace where the form value type is reduced to string, then verify that passing the resulting lens to Child preserves the branded email type without introducing the reported incompatibility.
Written by the indexing model from the issue text.
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} />
}
- Dominant language
- TypeScript
- Stars
- 150
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from react-hook-form/lenses
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
react-hook-form/lenses#53 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
react-hook-form/lenses#52 · 2 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
react-hook-form/lenses#51 · 1 comment · 3 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
react-hook-form/lenses#50 · 6 comments · 2 reactions ·
-
help wanted
Difficulty 4/5 3-5 days Newbie friendliness 35/100
react-hook-form/lenses#38 · 6 comments · 2 reactions ·
All issues in react-hook-form/lenses
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·