Skip to content

increased type safety via string literals #496

@dgreene1

Description

@dgreene1

We would get considerably better type safety out of many of the form instance functions if we used the keyof operator. For instance, this simple change would make it impossible to accidentally mispell the field that we're looking for.

export interface FormInstance<Values = any> {
    getFieldValue: (name: NamePath) => StoreValue;

to this:

export interface FormInstance<Values = any> {
    getFieldValue: <NamePath extends keyof FormFieldsAndValues>(name: NamePath) => FormFieldsAndValues[NamePath] | undefined;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions