diff --git a/.eslintignore b/.eslintignore index efe690abc8..bb7762f79f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,6 @@ components/**/*.js components/**/*.jsx +components/*/__tests__/type.tsx !.eslintrc.js -!components/*/__tests__/* +!components/*/__tests__/**/*.js !components/*/demo/* diff --git a/.jest.js b/.jest.js index e5d8201280..07234768a2 100644 --- a/.jest.js +++ b/.jest.js @@ -36,6 +36,7 @@ module.exports = { '!components/*/style/index.tsx', '!components/style/index.tsx', '!components/*/locale/index.tsx', + '!components/*/__tests__/**/type.tsx', ], transformIgnorePatterns, snapshotSerializers: [ diff --git a/components/form/Form.tsx b/components/form/Form.tsx index 6379f17302..383da9f67c 100755 --- a/components/form/Form.tsx +++ b/components/form/Form.tsx @@ -110,9 +110,14 @@ export interface FormComponentProps { form: WrappedFormUtils; } -// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/9951 +export type Diff = + ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T]; +export type Omit = Pick>; + export interface ComponentDecorator { - (component: React.ComponentClass): React.ComponentClass; +

( + component: React.ComponentClass

, + ): React.ComponentClass & TOwnProps>; } export default class Form extends React.Component { diff --git a/components/form/__tests__/type.tsx b/components/form/__tests__/type.tsx new file mode 100644 index 0000000000..d78ae02165 --- /dev/null +++ b/components/form/__tests__/type.tsx @@ -0,0 +1,36 @@ +/* tslint:disable */ +import React from 'react'; +import Form, { FormComponentProps } from '../Form'; + +// test Form.create on component without own props +class WithoutOwnProps extends React.Component { + state = { + foo: 'bar', + }; + render() { + return

foo
; + } +} + +const WithoutOwnPropsForm = Form.create()(WithoutOwnProps); + +; + +// test Form.create on component with own props +interface WithOwnPropsProps extends FormComponentProps { + name: string; +} + +class WithOwnProps extends React.Component { + state = { + foo: 'bar', + }; + + render() { + return
foo
; + } +} + +const WithOwnPropsForm = Form.create()(WithOwnProps); + +;