Added a more specific MetaSelector and FormMeta types to stronger type the object returned from the getFormMeta selector

This commit is contained in:
Luke Venn
2017-08-07 12:57:58 +01:00
parent c9bd9cf538
commit cd8057fe93
3 changed files with 21 additions and 9 deletions
+10
View File
@@ -12,6 +12,12 @@ import {
export type FieldValue = any;
export type FieldState = {
active?: boolean;
touched?: boolean;
visited?: boolean;
}
export type FieldType = "Field" | "FieldArray";
export interface DataShape {
@@ -26,6 +32,10 @@ export type FormWarnings<FormData extends DataShape> = {
[P in keyof FormData]?: ReactElement<any> | string | { _warning?: string };
};
export type FormMeta<FormData extends DataShape> = {
[P in keyof FormData]?: FieldState;
}
/**
* A component class or stateless function component.
* Workaround for: ComponentClass<P> | SFC<P> which does
+1 -7
View File
@@ -1,5 +1,5 @@
import { Action, Reducer } from "redux";
import { FieldType } from "../index";
import { FieldType, FieldState } from "../index";
export interface FormReducer extends Reducer<FormStateMap> {
/**
@@ -41,9 +41,3 @@ export interface RegisteredFieldState {
name: string;
type: FieldType;
}
export interface FieldState {
active?: boolean;
touched?: boolean;
visited?: boolean;
}
+10 -2
View File
@@ -1,4 +1,4 @@
import { DataShape, FormErrors } from "../index";
import { DataShape, FormErrors, FormMeta } from "../index";
/**
* A "selector" API to make it easier to connect() to form values. Creates a selector
@@ -26,6 +26,14 @@ export interface ErrorSelector {
<FormData extends DataShape>(formName: string): (state: any) => FormErrors<FormData>;
}
/**
* Get form field meta
*/
export interface MetaSelector {
<FormData extends DataShape, State>(formName: string): (state: State) => FormMeta<FormData>;
<FormData extends DataShape>(formName: string): (state: any) => FormMeta<FormData>;
}
/**
* Gets boolean info from form.
*/
@@ -42,7 +50,7 @@ export const getFormValues: DataSelector;
/**
* Returns the form's fields meta data, namely touched and visited.
*/
export const getFormMeta: DataSelector;
export const getFormMeta: MetaSelector;
/**
* Gets the form's initial values.