mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +08:00
Remove generic type from ComponentDecorator, fix #9331
This commit is contained in:
parent
2c95ea0e5e
commit
dc439bd7c3
@ -117,10 +117,10 @@ export type Diff<T extends string, U extends string> =
|
||||
({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
|
||||
export type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;
|
||||
|
||||
export interface ComponentDecorator<TOwnProps> {
|
||||
export interface ComponentDecorator {
|
||||
<P extends FormComponentProps>(
|
||||
component: React.ComponentClass<P> | React.SFC<P>,
|
||||
): React.ComponentClass<Omit<P, keyof FormComponentProps> & TOwnProps>;
|
||||
): React.ComponentClass<Omit<P, keyof FormComponentProps>>;
|
||||
}
|
||||
|
||||
export default class Form extends React.Component<FormProps, any> {
|
||||
@ -149,7 +149,7 @@ export default class Form extends React.Component<FormProps, any> {
|
||||
|
||||
static createFormField = createFormField;
|
||||
|
||||
static create = function<TOwnProps>(options: FormCreateOption<TOwnProps> = {}): ComponentDecorator<TOwnProps> {
|
||||
static create = function<TOwnProps>(options: FormCreateOption<TOwnProps> = {}): ComponentDecorator {
|
||||
return createDOMForm({
|
||||
fieldNameProp: 'id',
|
||||
...options,
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* tslint:disable */
|
||||
import * as React from 'react';
|
||||
import Form, { FormComponentProps } from '../Form';
|
||||
import Form, { FormComponentProps, FormCreateOption } from '../Form';
|
||||
|
||||
// test Form.create on component without own props
|
||||
class WithoutOwnProps extends React.Component<any, any> {
|
||||
@ -34,3 +34,28 @@ class WithOwnProps extends React.Component<WithOwnPropsProps, any> {
|
||||
const WithOwnPropsForm = Form.create()(WithOwnProps);
|
||||
|
||||
<WithOwnPropsForm name="foo" />;
|
||||
|
||||
// test Form.create with options
|
||||
interface WithCreateOptionsProps extends FormComponentProps {
|
||||
username: string;
|
||||
}
|
||||
|
||||
class WithCreateOptions extends React.Component<WithCreateOptionsProps, {}> {
|
||||
render() {
|
||||
return <div>foo</div>;
|
||||
}
|
||||
}
|
||||
|
||||
const mapPropsToFields = (props: WithCreateOptionsProps) => {
|
||||
const { username } = props;
|
||||
|
||||
return {
|
||||
username: Form.createFormField({ value: username })
|
||||
};
|
||||
};
|
||||
|
||||
const formOptions: FormCreateOption<WithCreateOptionsProps> = { mapPropsToFields };
|
||||
|
||||
const WithCreateOptionsForm = Form.create(formOptions)(WithCreateOptions);
|
||||
|
||||
<WithCreateOptionsForm username="foo" />
|
||||
|
Loading…
Reference in New Issue
Block a user