fix(types): external module type error (CompoundedComponent) (#38666)

* fix(types): external module type error (CompoundedComponent)

* refactor(types): rename and replace internal CompoundedComponent type
This commit is contained in:
Dave 2022-11-19 16:56:23 +08:00 committed by GitHub
parent 017f3ac248
commit d32a1fe274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 62 additions and 54 deletions

View File

@ -91,11 +91,11 @@ const CloseIcon: React.FC<CloseIconProps> = (props) => {
) : null; ) : null;
}; };
interface AlertInterface extends React.FC<AlertProps> { type CompoundedComponent = React.FC<AlertProps> & {
ErrorBoundary: typeof ErrorBoundary; ErrorBoundary: typeof ErrorBoundary;
} };
const Alert: AlertInterface = ({ const Alert: CompoundedComponent = ({
description, description,
prefixCls: customizePrefixCls, prefixCls: customizePrefixCls,
message, message,

View File

@ -6,11 +6,11 @@ export type { AnchorLinkProps } from './AnchorLink';
type InternalAnchorType = typeof InternalAnchor; type InternalAnchorType = typeof InternalAnchor;
interface AnchorInterface extends InternalAnchorType { type CompoundedComponent = InternalAnchorType & {
Link: typeof AnchorLink; Link: typeof AnchorLink;
} };
const Anchor = InternalAnchor as AnchorInterface; const Anchor = InternalAnchor as CompoundedComponent;
Anchor.Link = AnchorLink; Anchor.Link = AnchorLink;
export default Anchor; export default Anchor;

View File

@ -13,9 +13,9 @@ import { isPresetColor } from './utils';
export type { ScrollNumberProps } from './ScrollNumber'; export type { ScrollNumberProps } from './ScrollNumber';
interface CompoundedComponent extends React.FC<BadgeProps> { type CompoundedComponent = React.FC<BadgeProps> & {
Ribbon: typeof Ribbon; Ribbon: typeof Ribbon;
} };
export interface BadgeProps { export interface BadgeProps {
/** Number to show in badge */ /** Number to show in badge */

View File

@ -69,12 +69,12 @@ const addChildPath = (paths: string[], childPath: string, params: any) => {
return originalPaths; return originalPaths;
}; };
interface BreadcrumbInterface extends React.FC<BreadcrumbProps> { type CompoundedComponent = React.FC<BreadcrumbProps> & {
Item: typeof BreadcrumbItem; Item: typeof BreadcrumbItem;
Separator: typeof BreadcrumbSeparator; Separator: typeof BreadcrumbSeparator;
} };
const Breadcrumb: BreadcrumbInterface = ({ const Breadcrumb: CompoundedComponent = ({
prefixCls: customizePrefixCls, prefixCls: customizePrefixCls,
separator = '/', separator = '/',
style, style,

View File

@ -131,12 +131,13 @@ export type NativeButtonProps = {
export type ButtonProps = Partial<AnchorButtonProps & NativeButtonProps>; export type ButtonProps = Partial<AnchorButtonProps & NativeButtonProps>;
interface CompoundedComponent type CompoundedComponent = React.ForwardRefExoticComponent<
extends React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLElement>> { ButtonProps & React.RefAttributes<HTMLElement>
> & {
Group: typeof Group; Group: typeof Group;
/** @internal */ /** @internal */
__ANT_BUTTON: boolean; __ANT_BUTTON: boolean;
} };
type Loading = number | boolean; type Loading = number | boolean;

View File

@ -6,12 +6,13 @@ import Group from './Group';
export type { CheckboxChangeEvent, CheckboxProps } from './Checkbox'; export type { CheckboxChangeEvent, CheckboxProps } from './Checkbox';
export type { CheckboxGroupProps, CheckboxOptionType } from './Group'; export type { CheckboxGroupProps, CheckboxOptionType } from './Group';
interface CompoundedComponent type CompoundedComponent = React.ForwardRefExoticComponent<
extends React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLInputElement>> { CheckboxProps & React.RefAttributes<HTMLInputElement>
> & {
Group: typeof Group; Group: typeof Group;
/** @internal */ /** @internal */
__ANT_CHECKBOX: boolean; __ANT_CHECKBOX: boolean;
} };
const Checkbox = InternalCheckbox as CompoundedComponent; const Checkbox = InternalCheckbox as CompoundedComponent;

View File

@ -12,13 +12,14 @@ export type { PasswordProps } from './Password';
export type { SearchProps } from './Search'; export type { SearchProps } from './Search';
export type { TextAreaProps } from './TextArea'; export type { TextAreaProps } from './TextArea';
interface CompoundedComponent type CompoundedComponent = React.ForwardRefExoticComponent<
extends React.ForwardRefExoticComponent<InputProps & React.RefAttributes<InputRef>> { InputProps & React.RefAttributes<InputRef>
> & {
Group: typeof Group; Group: typeof Group;
Search: typeof Search; Search: typeof Search;
TextArea: typeof TextArea; TextArea: typeof TextArea;
Password: typeof Password; Password: typeof Password;
} };
const Input = InternalInput as CompoundedComponent; const Input = InternalInput as CompoundedComponent;

View File

@ -6,14 +6,14 @@ export type { SiderProps } from './Sider';
type InternalLayoutType = typeof InternalLayout; type InternalLayoutType = typeof InternalLayout;
interface LayoutType extends InternalLayoutType { type CompoundedComponent = InternalLayoutType & {
Header: typeof Header; Header: typeof Header;
Footer: typeof Footer; Footer: typeof Footer;
Content: typeof Content; Content: typeof Content;
Sider: typeof Sider; Sider: typeof Sider;
} };
const Layout = InternalLayout as LayoutType; const Layout = InternalLayout as CompoundedComponent;
Layout.Header = Header; Layout.Header = Header;
Layout.Footer = Footer; Layout.Footer = Footer;

View File

@ -53,12 +53,13 @@ interface MentionsEntity {
value: string; value: string;
} }
interface CompoundedComponent type CompoundedComponent = React.ForwardRefExoticComponent<
extends React.ForwardRefExoticComponent<MentionProps & React.RefAttributes<MentionsRef>> { MentionProps & React.RefAttributes<MentionsRef>
> & {
Option: typeof Option; Option: typeof Option;
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel; _InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
getMentions: (value: string, config?: MentionsConfig) => MentionsEntity[]; getMentions: (value: string, config?: MentionsConfig) => MentionsEntity[];
} };
const InternalMentions: React.ForwardRefRenderFunction<MentionsRef, MentionProps> = ( const InternalMentions: React.ForwardRefRenderFunction<MentionsRef, MentionProps> = (
{ {

View File

@ -19,13 +19,14 @@ export type MenuRef = {
focus: (options?: FocusOptions) => void; focus: (options?: FocusOptions) => void;
}; };
interface CompoundedComponent type CompoundedComponent = React.ForwardRefExoticComponent<
extends React.ForwardRefExoticComponent<MenuProps & React.RefAttributes<MenuRef>> { MenuProps & React.RefAttributes<MenuRef>
> & {
Divider: typeof MenuDivider; Divider: typeof MenuDivider;
Item: typeof Item; Item: typeof Item;
SubMenu: typeof SubMenu; SubMenu: typeof SubMenu;
ItemGroup: typeof ItemGroup; ItemGroup: typeof ItemGroup;
} };
const Menu = forwardRef<MenuRef, MenuProps>((props, ref) => { const Menu = forwardRef<MenuRef, MenuProps>((props, ref) => {
const menuRef = useRef<RcMenuRef>(null); const menuRef = useRef<RcMenuRef>(null);

View File

@ -14,13 +14,15 @@ export {
RadioProps, RadioProps,
} from './interface'; } from './interface';
export { Button, Group }; export { Button, Group };
interface CompoundedComponent
extends React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLElement>> { type CompoundedComponent = React.ForwardRefExoticComponent<
RadioProps & React.RefAttributes<HTMLElement>
> & {
Group: typeof Group; Group: typeof Group;
Button: typeof Button; Button: typeof Button;
/** @internal */ /** @internal */
__ANT_RADIO: boolean; __ANT_RADIO: boolean;
} };
const Radio = InternalRadio as CompoundedComponent; const Radio = InternalRadio as CompoundedComponent;
Radio.Button = Button; Radio.Button = Button;

View File

@ -77,13 +77,13 @@ function getParagraphBasicProps(hasAvatar: boolean, hasTitle: boolean): Skeleton
return basicProps; return basicProps;
} }
interface CompoundedComponent { type CompoundedComponent = {
Button: typeof SkeletonButton; Button: typeof SkeletonButton;
Avatar: typeof SkeletonAvatar; Avatar: typeof SkeletonAvatar;
Input: typeof SkeletonInput; Input: typeof SkeletonInput;
Image: typeof SkeletonImage; Image: typeof SkeletonImage;
Node: typeof SkeletonNode; Node: typeof SkeletonNode;
} };
const Skeleton: React.FC<SkeletonProps> & CompoundedComponent = (props) => { const Skeleton: React.FC<SkeletonProps> & CompoundedComponent = (props) => {
const { const {

View File

@ -151,9 +151,9 @@ const Space: React.FC<SpaceProps> = (props) => {
); );
}; };
interface CompoundedComponent extends React.FC<SpaceProps> { type CompoundedComponent = React.FC<SpaceProps> & {
Compact: typeof Compact; Compact: typeof Compact;
} };
const CompoundedSpace = Space as CompoundedComponent; const CompoundedSpace = Space as CompoundedComponent;
CompoundedSpace.Compact = Compact; CompoundedSpace.Compact = Compact;

View File

@ -47,11 +47,11 @@ export interface StepsProps {
items?: StepProps[]; items?: StepProps[];
} }
interface StepsType extends React.FC<StepsProps> { type CompoundedComponent = React.FC<StepsProps> & {
Step: typeof RcSteps.Step; Step: typeof RcSteps.Step;
} };
const Steps: StepsType = (props) => { const Steps: CompoundedComponent = (props) => {
const { const {
percent, percent,
size, size,

View File

@ -37,11 +37,12 @@ export interface SwitchProps {
id?: string; id?: string;
} }
interface CompoundedComponent type CompoundedComponent = React.ForwardRefExoticComponent<
extends React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLElement>> { SwitchProps & React.RefAttributes<HTMLElement>
> & {
/** @internal */ /** @internal */
__ANT_SWITCH: boolean; __ANT_SWITCH: boolean;
} };
const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>( const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
( (

View File

@ -554,7 +554,7 @@ const ForwardTable = React.forwardRef(InternalTable) as <RecordType extends obje
type InternalTableType = typeof ForwardTable; type InternalTableType = typeof ForwardTable;
interface TableInterface extends InternalTableType { type CompoundedComponent = InternalTableType & {
SELECTION_COLUMN: typeof SELECTION_COLUMN; SELECTION_COLUMN: typeof SELECTION_COLUMN;
EXPAND_COLUMN: typeof RcTable.EXPAND_COLUMN; EXPAND_COLUMN: typeof RcTable.EXPAND_COLUMN;
SELECTION_ALL: 'SELECT_ALL'; SELECTION_ALL: 'SELECT_ALL';
@ -563,9 +563,9 @@ interface TableInterface extends InternalTableType {
Column: typeof Column; Column: typeof Column;
ColumnGroup: typeof ColumnGroup; ColumnGroup: typeof ColumnGroup;
Summary: typeof Summary; Summary: typeof Summary;
} };
const Table = ForwardTable as TableInterface; const Table = ForwardTable as CompoundedComponent;
Table.SELECTION_COLUMN = SELECTION_COLUMN; Table.SELECTION_COLUMN = SELECTION_COLUMN;
Table.EXPAND_COLUMN = RcTable.EXPAND_COLUMN; Table.EXPAND_COLUMN = RcTable.EXPAND_COLUMN;

View File

@ -22,11 +22,11 @@ export interface TimelineProps {
children?: React.ReactNode; children?: React.ReactNode;
} }
interface TimelineType extends React.FC<TimelineProps> { type CompoundedComponent = React.FC<TimelineProps> & {
Item: React.FC<TimelineItemProps>; Item: React.FC<TimelineItemProps>;
} };
const Timeline: TimelineType = (props) => { const Timeline: CompoundedComponent = (props) => {
const { getPrefixCls, direction } = React.useContext(ConfigContext); const { getPrefixCls, direction } = React.useContext(ConfigContext);
const { const {
prefixCls: customizePrefixCls, prefixCls: customizePrefixCls,

View File

@ -256,15 +256,15 @@ const TreeSelectRef = React.forwardRef(InternalTreeSelect) as <
type InternalTreeSelectType = typeof TreeSelectRef; type InternalTreeSelectType = typeof TreeSelectRef;
interface TreeSelectInterface extends InternalTreeSelectType { type CompoundedComponent = InternalTreeSelectType & {
TreeNode: typeof TreeNode; TreeNode: typeof TreeNode;
SHOW_ALL: typeof SHOW_ALL; SHOW_ALL: typeof SHOW_ALL;
SHOW_PARENT: typeof SHOW_PARENT; SHOW_PARENT: typeof SHOW_PARENT;
SHOW_CHILD: typeof SHOW_CHILD; SHOW_CHILD: typeof SHOW_CHILD;
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel; _InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
} };
const TreeSelect = TreeSelectRef as TreeSelectInterface; const TreeSelect = TreeSelectRef as CompoundedComponent;
// We don't care debug panel // We don't care debug panel
/* istanbul ignore next */ /* istanbul ignore next */

View File

@ -12,15 +12,15 @@ export type {
} from './interface'; } from './interface';
type InternalUploadType = typeof InternalUpload; type InternalUploadType = typeof InternalUpload;
interface UploadInterface<T = any> extends InternalUploadType { type CompoundedComponent<T = any> = InternalUploadType & {
<U extends T>( <U extends T>(
props: React.PropsWithChildren<UploadProps<U>> & React.RefAttributes<any>, props: React.PropsWithChildren<UploadProps<U>> & React.RefAttributes<any>,
): React.ReactElement; ): React.ReactElement;
Dragger: typeof Dragger; Dragger: typeof Dragger;
LIST_IGNORE: string; LIST_IGNORE: string;
} };
const Upload = InternalUpload as UploadInterface; const Upload = InternalUpload as CompoundedComponent;
Upload.Dragger = Dragger; Upload.Dragger = Dragger;
Upload.LIST_IGNORE = LIST_IGNORE; Upload.LIST_IGNORE = LIST_IGNORE;