@@ -18,6 +18,7 @@ import {
1818 FormInterface ,
1919 FieldsDefinitions ,
2020 FormConfig ,
21+ PathsOf ,
2122} from "./models/FormInterface" ;
2223import { FieldPropsEnum } from "./models/FieldProps" ;
2324import { OptionsEnum } from "./models/OptionsModel" ;
@@ -184,21 +185,20 @@ export default class Form<F extends Record<string, any> = Record<string, any>> e
184185
185186 /**
186187 * Select a field by key with type inference.
187- * Provides autocomplete for field keys when the form is typed with a generic `F`.
188+ * Provides transparent autocomplete for both top-level keys (`keyof F`)
189+ * AND nested paths (`PathsOf<F>`) without any type annotations needed.
188190 *
189191 * @example
190- * // Top-level keys get autocomplete from keyof F:
192+ * // Top-level keys — autocomplete from keyof F:
191193 * form.$('username'); // returns Field<string>
192194 *
193195 * @example
194- * // For nested paths, use the `PathsOf` utility type:
195- * import { PathsOf } from 'mobx-react-form';
196- *
197- * function getField(form: Form<NestedClubFields>, path: PathsOf<NestedClubFields>) {
198- * return form.$(path); // path autocompletes to "club" | "club.name" | "members[].firstname" | ...
199- * }
196+ * // Nested paths — autocomplete from PathsOf<F>:
197+ * form.$('club'); // "club"
198+ * form.$('club.name'); // "club.name" ← autocomplete after dot!
199+ * form.$('members[].firstname'); // "members[].firstname"
200200 */
201- override $ ( key : keyof F ) : Field < F [ keyof F ] > {
201+ override $ ( key : keyof F | PathsOf < F > ) : Field < F [ keyof F ] > {
202202 return super . $ ( key as string ) as Field < F [ keyof F ] > ;
203203 }
204204
0 commit comments