From dc439bd7c387dec40f4448ebde4a03253d672cab Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Thu, 22 Feb 2018 15:52:35 +0800 Subject: [PATCH] Remove generic type from ComponentDecorator, fix #9331 --- components/form/Form.tsx | 6 +++--- components/form/__tests__/type.tsx | 27 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/components/form/Form.tsx b/components/form/Form.tsx index 373fe6f70d..6cd2867a5d 100755 --- a/components/form/Form.tsx +++ b/components/form/Form.tsx @@ -117,10 +117,10 @@ export type Diff = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T]; export type Omit = Pick>; -export interface ComponentDecorator { +export interface ComponentDecorator {

( component: React.ComponentClass

| React.SFC

, - ): React.ComponentClass & TOwnProps>; + ): React.ComponentClass>; } export default class Form extends React.Component { @@ -149,7 +149,7 @@ export default class Form extends React.Component { static createFormField = createFormField; - static create = function(options: FormCreateOption = {}): ComponentDecorator { + static create = function(options: FormCreateOption = {}): ComponentDecorator { return createDOMForm({ fieldNameProp: 'id', ...options, diff --git a/components/form/__tests__/type.tsx b/components/form/__tests__/type.tsx index 63d2a9608e..517b0e6c13 100644 --- a/components/form/__tests__/type.tsx +++ b/components/form/__tests__/type.tsx @@ -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 { @@ -34,3 +34,28 @@ class WithOwnProps extends React.Component { const WithOwnPropsForm = Form.create()(WithOwnProps); ; + +// test Form.create with options +interface WithCreateOptionsProps extends FormComponentProps { + username: string; +} + +class WithCreateOptions extends React.Component { + render() { + return

foo
; + } +} + +const mapPropsToFields = (props: WithCreateOptionsProps) => { + const { username } = props; + + return { + username: Form.createFormField({ value: username }) + }; +}; + +const formOptions: FormCreateOption = { mapPropsToFields }; + +const WithCreateOptionsForm = Form.create(formOptions)(WithCreateOptions); + +