-
Notifications
You must be signed in to change notification settings - Fork 11
Description
This lib is a huge win for composable forms, love it!
However, if you want to create a ComposableSubForm that expects a WideUnion, but the consumer only provides a narrower subset, it won’t work as expected.
Versions:
"@hookform/lenses": "^0.7.1",
"react-hook-form": "^7.56.2",
type WideUnion = "Foo" | "Bar" | "Baz"
type WideUnionSubset = "Foo" | "Bar"
function ComposeableSubForm({ lens }: { lens: Lens<WideUnion> }) {
return null
}
function Form() {
const { control } = useForm({
values: {
prop: "Foo" as WideUnionSubset,
},
})
const lens = useLens({ control })
// Error happens here:
return <ComposeableSubForm lens={lens.focus("prop")} />
}
Type 'Lens' is not assignable to type 'Lens'.
Type 'LensInterop & PrimitiveLens<"Foo">' is not assignable to type 'Lens'.
Type 'LensInterop & PrimitiveLens<"Foo">' is not assignable to type 'LensInterop & PrimitiveLens<"Baz">'.
Type 'LensInterop & PrimitiveLens<"Foo">' is not assignable to type 'LensInterop'.
The types of 'interop().control._subjects.state' are incompatible between these types.
Type 'FormStateSubjectRef<HookFormControlShim>' is not assignable to type 'FormStateSubjectRef<HookFormControlShim>'.
Type 'FormStateSubjectRef<HookFormControlShim>' is not assignable to type '{ readonly observers: Observer<Partial<FormState<HookFormControlShim>> & { name?: string | undefined; values?: HookFormControlShim | undefined; type?: EventType | undefined; }>[]; subscribe: (value: Observer<Partial<FormState<HookFormControlShim>> & { name?: string | undefined; values?: HookFormControlShim | undefined; type?: EventType | undefined; }>) => Subscription; unsubscribe: Noop; }'.
Types of property 'observers' are incompatible.
Type 'Observer<Partial<FormState<HookFormControlShim>> & { name?: string | undefined; values?: HookFormControlShim | undefined; type?: EventType | undefined; }>[]' is not assignable to type 'Observer<Partial<FormState<HookFormControlShim>> & { name?: string | undefined; values?: HookFormControlShim | undefined; type?: EventType | undefined; }>[]'.
Type 'Observer<Partial<FormState<HookFormControlShim>> & { name?: string | undefined; values?: HookFormControlShim | undefined; type?: EventType | undefined; }>' is not assignable to type 'Observer<Partial<FormState<HookFormControlShim>> & { name?: string | undefined; values?: HookFormControlShim | undefined; type?: EventType | undefined; }>'.
Type 'Partial<FormState<HookFormControlShim>> & { name?: string | undefined; values?: HookFormControlShim | undefined; type?: EventType | undefined; }' is not assignable to type 'Partial<FormState<HookFormControlShim>> & { name?: string | undefined; values?: HookFormControlShim | undefined; type?: EventType | undefined; }'.
Type 'Partial<FormState<HookFormControlShim>> & { name?: string | undefined; values?: HookFormControlShim | undefined; type?: EventType | undefined; }' is not assignable to type 'Partial<FormState<HookFormControlShim>>'.
Types of property 'defaultValues' are incompatible.
Type 'Readonly<{ DO_NOT_USE_HOOK_FORM_CONTROL_SHIM?: WideUnion | undefined; }> | undefined' is not assignable to type 'Readonly<{ DO_NOT_USE_HOOK_FORM_CONTROL_SHIM?: WideUnionSubset | undefined; }> | undefined'.
Type 'Readonly<{ DO_NOT_USE_HOOK_FORM_CONTROL_SHIM?: WideUnion | undefined; }>' is not assignable to type 'Readonly<{ DO_NOT_USE_HOOK_FORM_CONTROL_SHIM?: WideUnionSubset | undefined; }>'.
Types of property 'DO_NOT_USE_HOOK_FORM_CONTROL_SHIM' are incompatible.
Type 'WideUnion | undefined' is not assignable to type 'WideUnionSubset | undefined'.
Type '"Baz"' is not assignable to type 'WideUnionSubset | undefined'.ts(2322)