fix: form type (#7245)

This commit is contained in:
Wei Zhu 2017-08-18 17:21:18 +08:00 committed by Benjy Cui
parent 723da5e164
commit 145ed77c00
4 changed files with 46 additions and 3 deletions

View File

@ -1,5 +1,6 @@
components/**/*.js
components/**/*.jsx
components/*/__tests__/type.tsx
!.eslintrc.js
!components/*/__tests__/*
!components/*/__tests__/**/*.js
!components/*/demo/*

View File

@ -36,6 +36,7 @@ module.exports = {
'!components/*/style/index.tsx',
'!components/style/index.tsx',
'!components/*/locale/index.tsx',
'!components/*/__tests__/**/type.tsx',
],
transformIgnorePatterns,
snapshotSerializers: [

View File

@ -110,9 +110,14 @@ export interface FormComponentProps {
form: WrappedFormUtils;
}
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/9951
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> {
(component: React.ComponentClass<FormComponentProps & TOwnProps>): React.ComponentClass<TOwnProps>;
<P extends FormComponentProps>(
component: React.ComponentClass<P>,
): React.ComponentClass<Omit<P, keyof FormComponentProps> & TOwnProps>;
}
export default class Form extends React.Component<FormProps, any> {

View File

@ -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<any, any> {
state = {
foo: 'bar',
};
render() {
return <div>foo</div>;
}
}
const WithoutOwnPropsForm = Form.create()(WithoutOwnProps);
<WithoutOwnPropsForm />;
// test Form.create on component with own props
interface WithOwnPropsProps extends FormComponentProps {
name: string;
}
class WithOwnProps extends React.Component<WithOwnPropsProps, any> {
state = {
foo: 'bar',
};
render() {
return <div>foo</div>;
}
}
const WithOwnPropsForm = Form.create()(WithOwnProps);
<WithOwnPropsForm name="foo" />;