mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 03:31:47 +00:00
Added a more specific MetaSelector and FormMeta types to stronger type the object returned from the getFormMeta selector
This commit is contained in:
Vendored
+10
@@ -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
|
||||
|
||||
Vendored
+1
-7
@@ -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
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user