Skip to content

Commit

Permalink
fix(types): external module type error (CompoundedComponent)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangcch committed Nov 18, 2022
1 parent 2b994c3 commit 4c799c8
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 38 deletions.
6 changes: 3 additions & 3 deletions components/badge/index.tsx
Expand Up @@ -12,9 +12,9 @@ import { isPresetColor } from './utils';

export { ScrollNumberProps } from './ScrollNumber';

interface CompoundedComponent extends React.FC<BadgeProps> {
type CompoundedComponent = React.FC<BadgeProps> & {
Ribbon: typeof Ribbon;
}
};

export interface BadgeProps {
/** Number to show in badge */
Expand Down Expand Up @@ -133,7 +133,7 @@ const Badge: CompoundedComponent = ({
const displayNode =
!livingCount || typeof livingCount !== 'object'
? undefined
: cloneElement(livingCount, oriProps => ({
: cloneElement(livingCount, (oriProps) => ({
style: {
...mergedStyle,
...oriProps.style,
Expand Down
11 changes: 6 additions & 5 deletions components/button/button.tsx
Expand Up @@ -55,7 +55,7 @@ function insertSpace(child: React.ReactElement | string | number, needInserted:
function spaceChildren(children: React.ReactNode, needInserted: boolean) {
let isPrevChildPure: boolean = false;
const childList: React.ReactNode[] = [];
React.Children.forEach(children, child => {
React.Children.forEach(children, (child) => {
const type = typeof child;
const isCurrentChildPure = type === 'string' || type === 'number';
if (isPrevChildPure && isCurrentChildPure) {
Expand All @@ -70,7 +70,7 @@ function spaceChildren(children: React.ReactNode, needInserted: boolean) {
});

// Pass to React.Children.map to auto fill key
return React.Children.map(childList, child =>
return React.Children.map(childList, (child) =>
insertSpace(child as React.ReactElement | string | number, needInserted),
);
}
Expand Down Expand Up @@ -128,12 +128,13 @@ export type NativeButtonProps = {

export type ButtonProps = Partial<AnchorButtonProps & NativeButtonProps>;

interface CompoundedComponent
extends React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLElement>> {
type CompoundedComponent = React.ForwardRefExoticComponent<
ButtonProps & React.RefAttributes<HTMLElement>
> & {
Group: typeof Group;
/** @internal */
__ANT_BUTTON: boolean;
}
};

type Loading = number | boolean;

Expand Down
7 changes: 4 additions & 3 deletions components/checkbox/index.tsx
Expand Up @@ -6,12 +6,13 @@ import Group from './Group';
export { CheckboxChangeEvent, CheckboxProps } from './Checkbox';
export { CheckboxGroupProps, CheckboxOptionType } from './Group';

interface CompoundedComponent
extends React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLInputElement>> {
type CompoundedComponent = React.ForwardRefExoticComponent<
CheckboxProps & React.RefAttributes<HTMLInputElement>
> & {
Group: typeof Group;
/** @internal */
__ANT_CHECKBOX: boolean;
}
};

const Checkbox = InternalCheckbox as CompoundedComponent;

Expand Down
7 changes: 4 additions & 3 deletions components/input/index.tsx
Expand Up @@ -12,13 +12,14 @@ export { PasswordProps } from './Password';
export { SearchProps } from './Search';
export { TextAreaProps } from './TextArea';

interface CompoundedComponent
extends React.ForwardRefExoticComponent<InputProps & React.RefAttributes<InputRef>> {
type CompoundedComponent = React.ForwardRefExoticComponent<
InputProps & React.RefAttributes<InputRef>
> & {
Group: typeof Group;
Search: typeof Search;
TextArea: typeof TextArea;
Password: typeof Password;
}
};

const Input = InternalInput as CompoundedComponent;

Expand Down
9 changes: 5 additions & 4 deletions components/mentions/index.tsx
Expand Up @@ -48,11 +48,12 @@ interface MentionsEntity {
value: string;
}

interface CompoundedComponent
extends React.ForwardRefExoticComponent<MentionProps & React.RefAttributes<MentionsRef>> {
type CompoundedComponent = React.ForwardRefExoticComponent<
MentionProps & React.RefAttributes<MentionsRef>
> & {
Option: typeof Option;
getMentions: (value: string, config?: MentionsConfig) => MentionsEntity[];
}
};

const InternalMentions: React.ForwardRefRenderFunction<MentionsRef, MentionProps> = (
{
Expand Down Expand Up @@ -185,7 +186,7 @@ Mentions.getMentions = (value: string = '', config: MentionsConfig = {}): Mentio
.map((str = ''): MentionsEntity | null => {
let hitPrefix: string | null = null;

prefixList.some(prefixStr => {
prefixList.some((prefixStr) => {
const startStr = str.slice(0, prefixStr.length);
if (startStr === prefixStr) {
hitPrefix = prefixStr;
Expand Down
8 changes: 5 additions & 3 deletions components/radio/index.tsx
Expand Up @@ -14,13 +14,15 @@ export {
RadioProps,
} from './interface';
export { Button, Group };
interface CompoundedComponent
extends React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLElement>> {

type CompoundedComponent = React.ForwardRefExoticComponent<
RadioProps & React.RefAttributes<HTMLElement>
> & {
Group: typeof Group;
Button: typeof Button;
/** @internal */
__ANT_RADIO: boolean;
}
};

const Radio = InternalRadio as CompoundedComponent;
Radio.Button = Button;
Expand Down
6 changes: 3 additions & 3 deletions components/skeleton/Skeleton.tsx
Expand Up @@ -75,15 +75,15 @@ function getParagraphBasicProps(hasAvatar: boolean, hasTitle: boolean): Skeleton
return basicProps;
}

interface CompoundedComponent {
type CompoundedComponent = {
Button: typeof SkeletonButton;
Avatar: typeof SkeletonAvatar;
Input: typeof SkeletonInput;
Image: typeof SkeletonImage;
Node: typeof SkeletonNode;
}
};

const Skeleton: React.FC<SkeletonProps> & CompoundedComponent = props => {
const Skeleton: React.FC<SkeletonProps> & CompoundedComponent = (props) => {
const {
prefixCls: customizePrefixCls,
loading,
Expand Down
8 changes: 4 additions & 4 deletions components/space/index.tsx
Expand Up @@ -38,7 +38,7 @@ function getNumberSize(size: SpaceSize) {
return typeof size === 'string' ? spaceSize[size] : size || 0;
}

const Space: React.FC<SpaceProps> = props => {
const Space: React.FC<SpaceProps> = (props) => {
const { getPrefixCls, space, direction: directionConfig } = React.useContext(ConfigContext);

const {
Expand All @@ -58,7 +58,7 @@ const Space: React.FC<SpaceProps> = props => {

const [horizontalSize, verticalSize] = React.useMemo(
() =>
((Array.isArray(size) ? size : [size, size]) as [SpaceSize, SpaceSize]).map(item =>
((Array.isArray(size) ? size : [size, size]) as [SpaceSize, SpaceSize]).map((item) =>
getNumberSize(item),
),
[size],
Expand Down Expand Up @@ -146,9 +146,9 @@ const Space: React.FC<SpaceProps> = props => {
);
};

interface CompoundedComponent extends React.FC<SpaceProps> {
type CompoundedComponent = React.FC<SpaceProps> & {
Compact: typeof Compact;
}
};

const CompoundedSpace = Space as CompoundedComponent;
CompoundedSpace.Compact = Compact;
Expand Down
7 changes: 4 additions & 3 deletions components/switch/index.tsx
Expand Up @@ -35,11 +35,12 @@ export interface SwitchProps {
id?: string;
}

interface CompoundedComponent
extends React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLElement>> {
type CompoundedComponent = React.ForwardRefExoticComponent<
SwitchProps & React.RefAttributes<HTMLElement>
> & {
/** @internal */
__ANT_SWITCH: boolean;
}
};

const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
(
Expand Down
13 changes: 6 additions & 7 deletions components/tree/index.tsx
Expand Up @@ -5,9 +5,9 @@ import type { DataNode } from 'rc-tree/lib/interface';

import type { TreeProps } from './Tree';
import TreePure from './Tree';
import DirectoryTree from './DirectoryTree'
import DirectoryTree from './DirectoryTree';

export { DataNode }
export { DataNode };
export { EventDataNode } from 'rc-tree/lib/interface';
export { DirectoryTreeProps, ExpandAction as DirectoryTreeExpandAction } from './DirectoryTree';
export {
Expand All @@ -21,16 +21,15 @@ export {
TreeProps,
} from './Tree';


type CompoundedComponent = (<T extends BasicDataNode | DataNode = DataNode>(
props: React.PropsWithChildren<TreeProps<T>> & { ref?: React.Ref<RcTree> },
) => React.ReactElement) & {
TreeNode: typeof TreeNode;
DirectoryTree: typeof DirectoryTree;
};

const Tree = TreePure as unknown as CompoundedComponent
Tree.DirectoryTree = DirectoryTree
Tree.TreeNode = TreeNode
const Tree = TreePure as unknown as CompoundedComponent;
Tree.DirectoryTree = DirectoryTree;
Tree.TreeNode = TreeNode;

export default Tree;
export default Tree;

0 comments on commit 4c799c8

Please sign in to comment.