mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 09:26:06 +08:00
fix: form type (#7245)
This commit is contained in:
parent
723da5e164
commit
145ed77c00
@ -1,5 +1,6 @@
|
||||
components/**/*.js
|
||||
components/**/*.jsx
|
||||
components/*/__tests__/type.tsx
|
||||
!.eslintrc.js
|
||||
!components/*/__tests__/*
|
||||
!components/*/__tests__/**/*.js
|
||||
!components/*/demo/*
|
||||
|
1
.jest.js
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: [
|
||||
|
@ -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
Normal file
36
components/form/__tests__/type.tsx
Normal 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" />;
|
Loading…
Reference in New Issue
Block a user