Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increased type safety via string literals #496

Open
dgreene1 opened this issue Feb 12, 2021 · 1 comment
Open

increased type safety via string literals #496

dgreene1 opened this issue Feb 12, 2021 · 1 comment

Comments

@dgreene1
Copy link

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;
@dgreene1
Copy link
Author

If approved, I will submit this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant