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 a8fc788 commit 881947b
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 35 deletions.
6 changes: 3 additions & 3 deletions components/badge/index.tsx
Expand Up @@ -13,9 +13,9 @@ import { isPresetColor } from './utils';

export type { 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 @@ -137,7 +137,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 @@ -58,7 +58,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 @@ -73,7 +73,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 @@ -131,12 +131,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 type { CheckboxChangeEvent, CheckboxProps } from './Checkbox';
export type { 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 type { PasswordProps } from './Password';
export type { SearchProps } from './Search';
export type { 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 @@ -53,12 +53,13 @@ interface MentionsEntity {
value: string;
}

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

const InternalMentions: React.ForwardRefRenderFunction<MentionsRef, MentionProps> = (
{
Expand Down Expand Up @@ -203,7 +204,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
9 changes: 5 additions & 4 deletions components/menu/index.tsx
Expand Up @@ -19,20 +19,21 @@ export type MenuRef = {
focus: (options?: FocusOptions) => void;
};

interface CompoundedComponent
extends React.ForwardRefExoticComponent<MenuProps & React.RefAttributes<MenuRef>> {
type CompoundedComponent = React.ForwardRefExoticComponent<
MenuProps & React.RefAttributes<MenuRef>
> & {
Divider: typeof MenuDivider;
Item: typeof Item;
SubMenu: typeof SubMenu;
ItemGroup: typeof ItemGroup;
}
};

const Menu = forwardRef<MenuRef, MenuProps>((props, ref) => {
const menuRef = useRef<RcMenuRef>(null);
const context = React.useContext(SiderContext);

useImperativeHandle(ref, () => ({
focus: options => {
focus: (options) => {
menuRef.current?.focus(options);
},
menu: menuRef.current,
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 @@ -77,15 +77,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 @@ -40,7 +40,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 @@ -60,7 +60,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 @@ -151,9 +151,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 @@ -37,11 +37,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

0 comments on commit 881947b

Please sign in to comment.