import { FieldArrayInstance, FieldInstance, Form, ErrorsMap } from "houseform"; import { assertType } from "vitest"; import { ComponentProps } from "react"; interface TestObject { test: 1; other: { hello: { world: 2; }; }; } const specificErrorMap = 0 as unknown as ErrorsMap; const defaultErrorMap = 0 as unknown as ErrorsMap; assertType(specificErrorMap.other.hello.world); assertType(specificErrorMap.test); assertType(defaultErrorMap.other); assertType(defaultErrorMap.one); const FormProps = 0 as unknown as ComponentProps>; const onSubmit = FormProps["onSubmit"]; const onSubmitValues = 0 as unknown as Parameters< Exclude >[0]; const FormChildrenProps = 0 as unknown as Parameters< (typeof FormProps)["children"] >[0]; const getFieldValue = FormChildrenProps["getFieldValue"]; assertType(onSubmitValues); assertType(onSubmitValues); /** * Recognized dot-notation string is treated as a typed instance */ assertType | FieldArrayInstance<1> | undefined>( getFieldValue("test") ); assertType | FieldArrayInstance<2> | undefined>( getFieldValue("other.hello.world") ); /** * Unrecognized string is treated as any instance */ assertType( getFieldValue(`other["hello"].world`) );