While using this library I've discovered a curious type error.
function test<T>(lens: Lens<T>) {
useController(lens.interop())
}
doesn't typecheck. useController doesn't accept lens.interop() type.
One issue seems to be that, LensSelector type is defined like this:
type LensSelector<T> = [T] extends [any[]] ? ArrayLens<T> : [T] extends [FieldValues] ? ObjectLens<T> : [T] extends [boolean | true | false] ? PrimitiveLens<boolean> : [T] extends [null | undefined] ? never : PrimitiveLens<T>;
In which you can see PrimitiveLens<boolean>. This causes a typescript union of HookFormControlShim<T> | HookFormControlShim<boolean> (shortened for brevity) and that doesn't seem to me like it can pass the T generic check. If instead you replace PrimitiveLens<boolean> with PrimitiveLens<T> then the union goes away and we have now a proper HookFormControlShim<T>. I couldn't truly verify that this was a problem because of the second issue.
Unfortunately the second issue is beyond my comprehension. Seems like everything should work but they do not. When I tried different options, I got really weird results. Good luck!
This is my shortened tsconfig.json
{
"compilerOptions": {
"target": "es6",
"jsx": "react-jsx",
"strict": true,
"baseUrl": "src/main/frontend",
"module" : "es2020",
"moduleResolution": "Node",
"resolveJsonModule": true
},
}
While using this library I've discovered a curious type error.
doesn't typecheck. useController doesn't accept lens.interop() type.
One issue seems to be that, LensSelector type is defined like this:
In which you can see
PrimitiveLens<boolean>. This causes a typescript union ofHookFormControlShim<T> | HookFormControlShim<boolean>(shortened for brevity) and that doesn't seem to me like it can pass the T generic check. If instead you replacePrimitiveLens<boolean>withPrimitiveLens<T>then the union goes away and we have now a properHookFormControlShim<T>. I couldn't truly verify that this was a problem because of the second issue.Unfortunately the second issue is beyond my comprehension. Seems like everything should work but they do not. When I tried different options, I got really weird results. Good luck!
This is my shortened tsconfig.json
{ "compilerOptions": { "target": "es6", "jsx": "react-jsx", "strict": true, "baseUrl": "src/main/frontend", "module" : "es2020", "moduleResolution": "Node", "resolveJsonModule": true }, }