fix: form typescript definition (#16126)

* use redux-react ts define

* update doc

* follow origin rule
This commit is contained in:
zombieJ 2019-04-17 13:51:52 +08:00 committed by GitHub
parent df141914e9
commit fdcfabfa78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 10 deletions

View File

@ -6,11 +6,12 @@ import createFormField from 'rc-form/lib/createFormField';
import omit from 'omit.js';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import { ColProps } from '../grid/col';
import { Omit, tuple } from '../_util/type';
import { tuple } from '../_util/type';
import warning from '../_util/warning';
import FormItem, { FormLabelAlign } from './FormItem';
import { FIELD_META_PROP, FIELD_DATA_PROP } from './constants';
import { FormContext } from './context';
import { FormWrappedProps } from './interface';
type FormCreateOptionMessagesCallback = (...args: any[]) => string;
@ -193,12 +194,6 @@ export interface RcBaseFormProps {
wrappedComponentRef?: any;
}
export interface ComponentDecorator {
<P extends FormComponentProps>(
component: React.ComponentClass<P> | React.SFC<P>,
): React.ComponentClass<RcBaseFormProps & Omit<P, keyof FormComponentProps>>;
}
export default class Form extends React.Component<FormProps, any> {
static defaultProps = {
colon: true,
@ -222,9 +217,9 @@ export default class Form extends React.Component<FormProps, any> {
static createFormField = createFormField;
static create = function<TOwnProps>(
static create = function<TOwnProps extends FormComponentProps>(
options: FormCreateOption<TOwnProps> = {},
): ComponentDecorator {
): FormWrappedProps<TOwnProps> {
return createDOMForm({
fieldNameProp: 'id',
...options,

View File

@ -31,7 +31,7 @@ class WithOwnProps extends React.Component<WithOwnPropsProps, any> {
}
}
const WithOwnPropsForm = Form.create()(WithOwnProps);
const WithOwnPropsForm = Form.create<WithOwnPropsProps>()(WithOwnProps);
<WithOwnPropsForm name="foo" />;

View File

@ -0,0 +1,18 @@
import * as React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { Omit } from '../_util/type';
import { FormComponentProps } from './Form';
// Copy from @types/react-redux https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-redux/index.d.ts
export type ConnectedComponentClass<
C extends React.ComponentType<any>,
P
> = React.ComponentClass<JSX.LibraryManagedAttributes<C, P>> & hoistNonReactStatics.NonReactStatics<C> & {
WrappedComponent: C;
};
export type FormWrappedProps<TOwnProps extends FormComponentProps> =
<
C extends React.ComponentType
>(component: C)
=> ConnectedComponentClass<C, Omit<TOwnProps, keyof FormComponentProps>>;

View File

@ -44,6 +44,7 @@
"dependencies": {
"@ant-design/icons": "~1.2.0",
"@ant-design/icons-react": "~1.1.5",
"@types/hoist-non-react-statics": "^3.3.1",
"@types/react-slick": "^0.23.3",
"array-tree-filter": "^2.1.0",
"babel-runtime": "6.x",