Browse Source

type: remove tuple、tupleNum、ElementOf (#39478)

* type: remove tuple

* type: remove tuple

* type: remove tuple

* fix

* fix

* fix type

* fix type

* fix type

* fix type

* fix type

* Update ColorPicker.tsx

* Update components/badge/utils.tsx

Co-authored-by: MadCcc <1075746765@qq.com>

* fix type

* fix type

* fix type

* fix

* fix

* fix type

* fix type

* fix type

* update snap

* update snap

Co-authored-by: MadCcc <1075746765@qq.com>
pull/39524/head
lijianan 2 years ago
committed by GitHub
parent
commit
12543277b7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      components/_util/colors.ts
  2. 4
      components/_util/motion.tsx
  3. 4
      components/_util/statusUtils.tsx
  4. 11
      components/_util/type.ts
  5. 2
      components/badge/utils.tsx
  6. 10
      components/button/button.tsx
  7. 3
      components/date-picker/generatePicker/index.tsx
  8. 3
      components/drawer/index.tsx
  9. 5
      components/dropdown/dropdown.tsx
  10. 3
      components/form/FormItem/index.tsx
  11. 12
      components/grid/row.tsx
  12. 3
      components/input/ClearableLabeledInput.tsx
  13. 5
      components/progress/progress.tsx
  14. 4
      components/spin/index.tsx
  15. 4
      components/table/interface.tsx
  16. 4
      components/tag/index.tsx
  17. 1
      components/tooltip/index.tsx
  18. 6
      components/transfer/ListBody.tsx
  19. 3
      components/typography/Title.tsx

20
components/_util/colors.ts

@ -1,9 +1,12 @@
import type { ElementOf } from './type';
import { tuple } from './type';
export const PresetStatusColorTypes = [
'success',
'processing',
'error',
'default',
'warning',
] as const;
export const PresetStatusColorTypes = tuple('success', 'processing', 'error', 'default', 'warning');
// eslint-disable-next-line import/prefer-default-export
export const PresetColorTypes = tuple(
export const PresetColorTypes = [
'pink',
'red',
'yellow',
@ -17,7 +20,8 @@ export const PresetColorTypes = tuple(
'volcano',
'gold',
'lime',
);
] as const;
export type PresetColorType = ElementOf<typeof PresetColorTypes>;
export type PresetStatusColorType = ElementOf<typeof PresetStatusColorTypes>;
export type PresetColorType = typeof PresetColorTypes[number];
export type PresetStatusColorType = typeof PresetStatusColorTypes[number];

4
components/_util/motion.tsx

@ -1,6 +1,5 @@
import type { CSSMotionProps, MotionEndEventHandler, MotionEventHandler } from 'rc-motion';
import type { MotionEvent } from 'rc-motion/lib/interface';
import { tuple } from './type';
// ================== Collapse Motion ==================
const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 });
@ -26,7 +25,8 @@ const initCollapseMotion = (rootCls: string = 'ant'): CSSMotionProps => ({
motionDeadline: 500,
});
const SelectPlacements = tuple('bottomLeft', 'bottomRight', 'topLeft', 'topRight');
const SelectPlacements = ['bottomLeft', 'bottomRight', 'topLeft', 'topRight'] as const;
export type SelectCommonPlacement = typeof SelectPlacements[number];
const getTransitionDirection = (placement: SelectCommonPlacement | undefined) => {

4
components/_util/statusUtils.tsx

@ -1,8 +1,8 @@
import classNames from 'classnames';
import type { ValidateStatus } from '../form/FormItem';
import { tuple } from './type';
const InputStatuses = tuple('warning', 'error', '');
const InputStatuses = ['warning', 'error', ''] as const;
export type InputStatus = typeof InputStatuses[number];
export function getStatusClassNames(

11
components/_util/type.ts

@ -1,13 +1,2 @@
// https://stackoverflow.com/questions/46176165/ways-to-get-string-literal-type-of-array-values-without-enum-overhead
export const tuple = <T extends string[]>(...args: T) => args;
export const tupleNum = <T extends number[]>(...args: T) => args;
/**
* https://stackoverflow.com/a/59187769 Extract the type of an element of an array/tuple without
* performing indexing
*/
export type ElementOf<T> = T extends (infer E)[] ? E : T extends readonly (infer F)[] ? F : never;
/** https://github.com/Microsoft/TypeScript/issues/29729 */
export type LiteralUnion<T extends U, U> = T | (U & {});

2
components/badge/utils.tsx

@ -2,5 +2,5 @@ import { PresetColorTypes } from '../_util/colors';
// eslint-disable-next-line import/prefer-default-export
export function isPresetColor(color?: string): boolean {
return (PresetColorTypes as any[]).includes(color);
return PresetColorTypes.includes(color as any);
}

10
components/button/button.tsx

@ -2,14 +2,12 @@
import classNames from 'classnames';
import omit from 'rc-util/lib/omit';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
import DisabledContext from '../config-provider/DisabledContext';
import type { SizeType } from '../config-provider/SizeContext';
import SizeContext from '../config-provider/SizeContext';
import { useCompactItemContext } from '../space/Compact';
import { cloneElement, isFragment } from '../_util/reactNode';
import { tuple } from '../_util/type';
import warning from '../_util/warning';
import Wave from '../_util/wave';
import Group, { GroupSizeContext } from './button-group';
@ -78,11 +76,13 @@ function spaceChildren(children: React.ReactNode, needInserted: boolean) {
);
}
const ButtonTypes = tuple('default', 'primary', 'ghost', 'dashed', 'link', 'text');
const ButtonTypes = ['default', 'primary', 'ghost', 'dashed', 'link', 'text'] as const;
export type ButtonType = typeof ButtonTypes[number];
const ButtonShapes = tuple('default', 'circle', 'round');
const ButtonShapes = ['default', 'circle', 'round'] as const;
export type ButtonShape = typeof ButtonShapes[number];
const ButtonHTMLTypes = tuple('submit', 'button', 'reset');
const ButtonHTMLTypes = ['submit', 'button', 'reset'] as const;
export type ButtonHTMLType = typeof ButtonHTMLTypes[number];
export type LegacyButtonType = ButtonType | 'danger';

3
components/date-picker/generatePicker/index.tsx

@ -14,7 +14,6 @@ import type {
import type { SizeType } from '../../config-provider/SizeContext';
import type { TimePickerLocale } from '../../time-picker';
import type { InputStatus } from '../../_util/statusUtils';
import { tuple } from '../../_util/type';
import PickerButton from '../PickerButton';
import generateRangePicker from './generateRangePicker';
import generateSinglePicker from './generateSinglePicker';
@ -70,7 +69,7 @@ export function getTimeProps<DateType, DisabledTime>(
showTime: showTimeObj,
};
}
const DataPickerPlacements = tuple('bottomLeft', 'bottomRight', 'topLeft', 'topRight');
const DataPickerPlacements = ['bottomLeft', 'bottomRight', 'topLeft', 'topRight'] as const;
type DataPickerPlacement = typeof DataPickerPlacements[number];
type InjectDefaultProps<Props> = Omit<

3
components/drawer/index.tsx

@ -6,7 +6,6 @@ import * as React from 'react';
import { ConfigContext } from '../config-provider';
import { NoFormStyle } from '../form/context';
import { getTransitionName } from '../_util/motion';
import { tuple } from '../_util/type';
import warning from '../_util/warning';
import DrawerPanel from './DrawerPanel';
import type { DrawerPanelProps } from './DrawerPanel';
@ -15,7 +14,7 @@ import type { DrawerPanelProps } from './DrawerPanel';
import useStyle from './style';
import { NoCompactStyle } from '../space/Compact';
const SizeTypes = tuple('default', 'large');
const SizeTypes = ['default', 'large'] as const;
type sizeType = typeof SizeTypes[number];
export interface PushState {

5
components/dropdown/dropdown.tsx

@ -11,13 +11,12 @@ import { OverrideProvider } from '../menu/OverrideContext';
import genPurePanel from '../_util/PurePanel';
import getPlacements from '../_util/placements';
import { cloneElement } from '../_util/reactNode';
import { tuple } from '../_util/type';
import warning from '../_util/warning';
import { NoCompactStyle } from '../space/Compact';
import DropdownButton from './dropdown-button';
import useStyle from './style';
const Placements = tuple(
const Placements = [
'topLeft',
'topCenter',
'topRight',
@ -26,7 +25,7 @@ const Placements = tuple(
'bottomRight',
'top',
'bottom',
);
] as const;
type Placement = typeof Placements[number];

3
components/form/FormItem/index.tsx

@ -9,7 +9,6 @@ import * as React from 'react';
import useFormItemStatus from '../hooks/useFormItemStatus';
import { ConfigContext } from '../../config-provider';
import { cloneElement, isValidElement } from '../../_util/reactNode';
import { tuple } from '../../_util/type';
import warning from '../../_util/warning';
import { FormContext, NoStyleItemContext } from '../context';
import type { FormItemInputProps } from '../FormItemInput';
@ -28,7 +27,7 @@ interface FieldError {
warnings: string[];
}
const ValidateStatuses = tuple('success', 'warning', 'error', 'validating', '');
const ValidateStatuses = ['success', 'warning', 'error', 'validating', ''] as const;
export type ValidateStatus = typeof ValidateStatuses[number];
type RenderChildren<Values = any> = (form: FormInstance<Values>) => React.ReactNode;

12
components/grid/row.tsx

@ -4,12 +4,18 @@ import { ConfigContext } from '../config-provider';
import useFlexGapSupport from '../_util/hooks/useFlexGapSupport';
import type { Breakpoint, ScreenMap } from '../_util/responsiveObserve';
import ResponsiveObserve, { responsiveArray } from '../_util/responsiveObserve';
import { tuple } from '../_util/type';
import RowContext from './RowContext';
import { useRowStyle } from './style';
const RowAligns = tuple('top', 'middle', 'bottom', 'stretch');
const RowJustify = tuple('start', 'end', 'center', 'space-around', 'space-between', 'space-evenly');
const RowAligns = ['top', 'middle', 'bottom', 'stretch'] as const;
const RowJustify = [
'start',
'end',
'center',
'space-around',
'space-between',
'space-evenly',
] as const;
type Responsive = 'xxl' | 'xl' | 'lg' | 'md' | 'sm' | 'xs';
type ResponsiveLike<T> = {

3
components/input/ClearableLabeledInput.tsx

@ -8,10 +8,9 @@ import { FormItemInputContext } from '../form/context';
import { cloneElement } from '../_util/reactNode';
import type { InputStatus } from '../_util/statusUtils';
import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
import { tuple } from '../_util/type';
import type { InputProps } from './Input';
const ClearableInputType = tuple('text', 'input');
const ClearableInputType = ['text', 'input'] as const;
function hasAddon(props: InputProps | ClearableInputProps) {
return !!(props.addonBefore || props.addonAfter);

5
components/progress/progress.tsx

@ -7,7 +7,6 @@ import omit from 'rc-util/lib/omit';
import * as React from 'react';
import type { ConfigConsumerProps } from '../config-provider';
import { ConfigContext } from '../config-provider';
import { tuple } from '../_util/type';
import warning from '../_util/warning';
import Circle from './Circle';
import Line from './Line';
@ -15,9 +14,9 @@ import Steps from './Steps';
import { getSuccessPercent, validProgress } from './utils';
import useStyle from './style';
const ProgressTypes = tuple('line', 'circle', 'dashboard');
const ProgressTypes = ['line', 'circle', 'dashboard'] as const;
export type ProgressType = typeof ProgressTypes[number];
const ProgressStatuses = tuple('normal', 'exception', 'active', 'success');
const ProgressStatuses = ['normal', 'exception', 'active', 'success'] as const;
export type ProgressSize = 'default' | 'small';
export type StringGradients = { [percentage: string]: string };
type FromToGradients = { from: string; to: string };

4
components/spin/index.tsx

@ -5,11 +5,9 @@ import * as React from 'react';
import type { ConfigConsumerProps } from '../config-provider';
import { ConfigConsumer, ConfigContext } from '../config-provider';
import { cloneElement, isValidElement } from '../_util/reactNode';
import { tuple } from '../_util/type';
import useStyle from './style/index';
const SpinSizes = tuple('small', 'default', 'large');
const SpinSizes = ['small', 'default', 'large'] as const;
export type SpinSize = typeof SpinSizes[number];
export type SpinIndicator = React.ReactElement<HTMLElement>;

4
components/table/interface.tsx

@ -9,9 +9,7 @@ import type { CheckboxProps } from '../checkbox';
import type { PaginationProps } from '../pagination';
import type { TooltipProps } from '../tooltip';
import type { Breakpoint } from '../_util/responsiveObserve';
import { tuple } from '../_util/type';
import type { INTERNAL_SELECTION_ITEM } from './hooks/useSelection';
// import { TableAction } from './Table';
export { GetRowKey, ExpandableConfig };
@ -45,7 +43,7 @@ export interface TableLocale {
export type SortOrder = 'descend' | 'ascend' | null;
const TableActions = tuple('paginate', 'sort', 'filter');
const TableActions = ['paginate', 'sort', 'filter'] as const;
export type TableAction = typeof TableActions[number];
export type CompareFn<T> = (a: T, b: T, sortOrder?: SortOrder) => number;

4
components/tag/index.tsx

@ -1,16 +1,14 @@
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classNames from 'classnames';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
import type { PresetColorType, PresetStatusColorType } from '../_util/colors';
import { PresetColorTypes, PresetStatusColorTypes } from '../_util/colors';
import type { LiteralUnion } from '../_util/type';
import Wave from '../_util/wave';
import warning from '../_util/warning';
import CheckableTag from './CheckableTag';
import useStyle from './style';
import type { LiteralUnion } from '../_util/type';
export type { CheckableTagProps } from './CheckableTag';

1
components/tooltip/index.tsx

@ -14,7 +14,6 @@ import { cloneElement, isValidElement, isFragment } from '../_util/reactNode';
import type { LiteralUnion } from '../_util/type';
import warning from '../_util/warning';
import PurePanel from './PurePanel';
import useStyle from './style';
import { parseColor } from './util';

6
components/transfer/ListBody.tsx

@ -2,14 +2,12 @@ import classNames from 'classnames';
import * as React from 'react';
import type { KeyWiseTransferItem } from '.';
import Pagination from '../pagination';
import type { ElementOf } from '../_util/type';
import { tuple } from '../_util/type';
import type { PaginationType } from './interface';
import type { RenderedItem, TransferListProps } from './list';
import ListItem from './ListItem';
export const OmitProps = tuple('handleFilter', 'handleClear', 'checkedKeys');
export type OmitProp = ElementOf<typeof OmitProps>;
export const OmitProps = ['handleFilter', 'handleClear', 'checkedKeys'] as const;
export type OmitProp = typeof OmitProps[number];
type PartialTransferListProps<RecordType> = Omit<TransferListProps<RecordType>, OmitProp>;
export interface TransferListBodyProps<RecordType> extends PartialTransferListProps<RecordType> {

3
components/typography/Title.tsx

@ -1,10 +1,9 @@
import * as React from 'react';
import { tupleNum } from '../_util/type';
import warning from '../_util/warning';
import type { BlockProps } from './Base';
import Base from './Base';
const TITLE_ELE_LIST = tupleNum(1, 2, 3, 4, 5);
const TITLE_ELE_LIST = [1, 2, 3, 4, 5] as const;
export interface TitleProps
extends Omit<BlockProps<'h1' | 'h2' | 'h3' | 'h4' | 'h5'>, 'strong'>,

Loading…
Cancel
Save