Browse Source

fix: form type (#7245)

pull/7259/head
Wei Zhu 7 years ago
committed by Benjy Cui
parent
commit
145ed77c00
  1. 3
      .eslintignore
  2. 1
      .jest.js
  3. 9
      components/form/Form.tsx
  4. 36
      components/form/__tests__/type.tsx

3
.eslintignore

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

1
.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: [

9
components/form/Form.tsx

@ -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> {

36
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<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" />;
Loading…
Cancel
Save