-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
help wantedExtra attention is neededExtra attention is needed
Description
In current implementation it is not possible to pass lens with wide type to lens with narrow type.
For example this code will not work:
function Form() {
const { control } = useForm<{ child: 'a' | 'b' | 'c' }>();
const lens = useLens({ control });
// Will be a type error, however it should be fine
return <ChildForm lens={lens} />;
}
function ChildForm({ lens }: { lens: Lens<{ child: 'a' | 'b' }> }) {
return null;
}
Because of that it is not possible to pass a union type:
function Form() {
const { control } = useForm<{ type: 'a'; a: string } | { type: 'b'; b: string }>();
const lens = useLens({ control });
// Has a type error
return <ChildForm lens={lens} />;
}
function ChildForm({ lens }: { lens: Lens<{ type: 'a'; a: string }> }) {
return null;
}
And the same with optional fields:
function Form() {
const { control } = useForm<{ child?: string }>();
const lens = useLens({ control });
// Still an error, but should work
return <ChildForm lens={lens} />;
}
function ChildForm({ lens }: { lens: Lens<{ child: string }> }) {
return null;
}
SeokminHong
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed