Skip to content

Commit

Permalink
feat: tsconfig enable strict (ant-design#47998)
Browse files Browse the repository at this point in the history
* feat: tsconfig enable strict

* feat: add no-explicit-any

* feat: strict

* feat: as THEME

* feat: 优化 keys 类型写法

* feat: demo remove any

* feat: as number

* feat: this any

* feat: add eslint

* feat: cascader

* feat: props any

* feat: remove any

* feat: remove any

* feat: any 提示错误

* feat: remove any

* feat: add eslint

* feat: 允许 T = any 存在

* feat: color funciton

* feat: 恢复 lint

* feat: merge master

* feat: as ReactElement

* feat: type
  • Loading branch information
crazyair authored Apr 1, 2024
1 parent 4eaa664 commit 14a1e6b
Show file tree
Hide file tree
Showing 136 changed files with 503 additions and 431 deletions.
2 changes: 1 addition & 1 deletion .dumi/pages/index/components/Theme/ThemePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const ThemePicker: React.FC<ThemePickerProps> = (props) => {
const [locale] = useLocale(locales);
return (
<Flex gap="large" wrap="wrap">
{Object.keys(THEMES).map<React.ReactNode>((theme: THEME, index) => (
{(Object.keys(THEMES) as (keyof typeof THEMES)[]).map<React.ReactNode>((theme, index) => (
<Flex vertical gap="small" justify="center" align="center" key={theme}>
<label
onClick={() => onChange?.(theme)}
Expand Down
2 changes: 1 addition & 1 deletion components/_util/PurePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const genPurePanel = <ComponentProps extends BaseProps = BaseProps>(

if (typeof ResizeObserver !== 'undefined') {
const resizeObserver = new ResizeObserver((entries) => {
const element: HTMLDivElement = entries[0].target as any;
const element = entries[0].target as HTMLDivElement;
setPopupHeight(element.offsetHeight + 8);
setPopupWidth(element.offsetWidth);
});
Expand Down
8 changes: 4 additions & 4 deletions components/_util/responsiveObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ export default function useResponsiveObserver() {
if (!subscribers.size) this.unregister();
},
unregister() {
Object.keys(responsiveMap).forEach((screen: Breakpoint) => {
const matchMediaQuery = responsiveMap[screen];
Object.keys(responsiveMap).forEach((screen) => {
const matchMediaQuery = responsiveMap[screen as Breakpoint];
const handler = this.matchHandlers[matchMediaQuery];
handler?.mql.removeListener(handler?.listener);
});
subscribers.clear();
},
register() {
Object.keys(responsiveMap).forEach((screen: Breakpoint) => {
const matchMediaQuery = responsiveMap[screen];
Object.keys(responsiveMap).forEach((screen) => {
const matchMediaQuery = responsiveMap[screen as Breakpoint];
const listener = ({ matches }: { matches: boolean }) => {
this.dispatch({
...screens,
Expand Down
6 changes: 3 additions & 3 deletions components/affix/__tests__/Affix.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const AffixMounter: React.FC<AffixProps> = (props) => {
container.current.addEventListener = jest
.fn()
.mockImplementation((event: keyof HTMLElementEventMap, cb: (ev: Event) => void) => {
events[event] = cb;
(events as any)[event] = cb;
});
}
}, []);
Expand All @@ -37,8 +37,8 @@ const AffixMounter: React.FC<AffixProps> = (props) => {
};

describe('Affix Render', () => {
rtlTest(Affix);
accessibilityTest(Affix);
rtlTest(Affix as any);
accessibilityTest(Affix as any);

const domMock = jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect');

Expand Down
6 changes: 4 additions & 2 deletions components/affix/__tests__/demo.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
import * as React from 'react';
import { spyElementPrototype } from 'rc-util/lib/test/domHook';

import demoTest, { rootPropsTest } from '../../../tests/shared/demoTest';

demoTest('affix', {
Expand All @@ -16,10 +17,11 @@ rootPropsTest(
{
beforeRender: () => {
spyElementPrototype(HTMLElement, 'getBoundingClientRect', function getBoundingClientRect() {
// @ts-ignore
if (this.id === 'holder') {
return { top: 0, bottom: 100 };
}

// @ts-ignore
if (this.className === 'fixed') {
return { top: -100, bottom: -100 };
}
Expand Down
2 changes: 1 addition & 1 deletion components/calendar/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ describe('Calendar', () => {
const onTypeChange = jest.fn();
const value = Dayjs('2018-12-03');
const wrapper = render(
<Header
<Header<Dayjs.Dayjs>
prefixCls="ant-picker-calendar"
generateConfig={dayjsGenerateConfig}
onModeChange={onTypeChange}
Expand Down
3 changes: 2 additions & 1 deletion components/calendar/generateCalendar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import classNames from 'classnames';
import type { BasePickerPanelProps as RcBasePickerPanelProps } from 'rc-picker';
import { PickerPanel as RCPickerPanel } from 'rc-picker';
import type { GenerateConfig } from 'rc-picker/lib/generate';
import type { CellRenderInfo } from 'rc-picker/lib/interface';
Expand Down Expand Up @@ -246,7 +247,7 @@ function generateCalendar<DateType extends AnyObject>(generateConfig: GenerateCo

const [contextLocale] = useLocale('Calendar', getDefaultLocale);

const mergedCellRender = (current: DateType, info: CellRenderInfo<DateType>) => {
const mergedCellRender: RcBasePickerPanelProps['cellRender'] = (current, info) => {
if (info.type === 'date') {
return dateRender(current, info);
}
Expand Down
2 changes: 1 addition & 1 deletion components/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const Card = React.forwardRef<HTMLDivElement, CardProps>((props, ref) => {

const isContainGrid = React.useMemo<boolean>(() => {
let containGrid = false;
React.Children.forEach(children, (element: JSX.Element) => {
React.Children.forEach(children as React.ReactElement, (element: JSX.Element) => {
if (element && element.type && element.type === Grid) {
containGrid = true;
}
Expand Down
3 changes: 2 additions & 1 deletion components/cascader/demo/change-on-select.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Cascader } from 'antd';
import type { SingleCascaderProps } from 'antd/es/cascader';

interface Option {
value: string;
Expand Down Expand Up @@ -42,7 +43,7 @@ const options: Option[] = [
},
];

const onChange = (value: string[]) => {
const onChange: SingleCascaderProps<Option>['onChange'] = (value) => {
console.log(value);
};

Expand Down
2 changes: 1 addition & 1 deletion components/cascader/demo/custom-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const handleAreaClick = (
console.log('clicked', label, option);
};

const displayRender = (labels: string[], selectedOptions: DefaultOptionType[]) =>
const displayRender: CascaderProps<Option>['displayRender'] = (labels, selectedOptions = []) =>
labels.map((label, i) => {
const option = selectedOptions[i];
if (i === labels.length - 1) {
Expand Down
3 changes: 2 additions & 1 deletion components/cascader/demo/custom-trigger.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import { Cascader } from 'antd';
import type { SingleCascaderProps } from 'antd/es/cascader';

interface Option {
value: string;
Expand Down Expand Up @@ -33,7 +34,7 @@ const options: Option[] = [
const App: React.FC = () => {
const [text, setText] = useState('Unselect');

const onChange = (_: string[], selectedOptions: Option[]) => {
const onChange: SingleCascaderProps<Option>['onChange'] = (_, selectedOptions) => {
setText(selectedOptions.map((o) => o.label).join(', '));
};

Expand Down
3 changes: 2 additions & 1 deletion components/cascader/demo/default-value.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Cascader } from 'antd';
import type { SingleCascaderProps } from 'antd/es/cascader';

interface Option {
value: string;
Expand Down Expand Up @@ -42,7 +43,7 @@ const options: Option[] = [
},
];

const onChange = (value: string[]) => {
const onChange: SingleCascaderProps<Option>['onChange'] = (value) => {
console.log(value);
};

Expand Down
3 changes: 2 additions & 1 deletion components/cascader/demo/disabled-option.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Cascader } from 'antd';
import type { SingleCascaderProps } from 'antd/es/cascader';

interface Option {
value: string;
Expand Down Expand Up @@ -44,7 +45,7 @@ const options: Option[] = [
},
];

const onChange = (value: string[]) => {
const onChange: SingleCascaderProps<Option>['onChange'] = (value) => {
console.log(value);
};

Expand Down
3 changes: 2 additions & 1 deletion components/cascader/demo/fields-name.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Cascader } from 'antd';
import type { SingleCascaderProps } from 'antd/es/cascader';

interface Option {
code: string;
Expand Down Expand Up @@ -42,7 +43,7 @@ const options: Option[] = [
},
];

const onChange = (value: string[]) => {
const onChange: SingleCascaderProps<Option>['onChange'] = (value) => {
console.log(value);
};

Expand Down
3 changes: 2 additions & 1 deletion components/cascader/demo/hover.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Cascader } from 'antd';
import type { SingleCascaderProps } from 'antd/es/cascader';

interface Option {
value: string;
Expand Down Expand Up @@ -42,7 +43,7 @@ const options: Option[] = [
},
];

const onChange = (value: string[]) => {
const onChange: SingleCascaderProps<Option>['onChange'] = (value) => {
console.log(value);
};

Expand Down
3 changes: 2 additions & 1 deletion components/cascader/demo/multiple.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Cascader } from 'antd';
import type { MultipleCascaderProps } from 'antd/es/cascader';

interface Option {
value: string | number;
Expand Down Expand Up @@ -43,7 +44,7 @@ const options: Option[] = [
},
];

const onChange = (value: string[][]) => {
const onChange: MultipleCascaderProps<Option>['onChange'] = (value) => {
console.log(value);
};

Expand Down
9 changes: 7 additions & 2 deletions components/cascader/demo/panel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Cascader, Flex } from 'antd';
import type { MultipleCascaderProps, SingleCascaderProps } from 'antd/es/cascader';

interface Option {
value: string | number;
Expand Down Expand Up @@ -42,14 +43,18 @@ const options: Option[] = [
},
];

const onChange = (value: string[]) => {
const onChange: SingleCascaderProps<Option>['onChange'] = (value) => {
console.log(value);
};

const onMultipleChange: MultipleCascaderProps<Option>['onChange'] = (value) => {
console.log(value);
};

const App: React.FC = () => (
<Flex vertical gap="small" align="flex-start">
<Cascader.Panel options={options} onChange={onChange} />
<Cascader.Panel multiple options={options} onChange={onChange} />
<Cascader.Panel multiple options={options} onChange={onMultipleChange} />
<Cascader.Panel />
</Flex>
);
Expand Down
5 changes: 3 additions & 2 deletions components/cascader/demo/search.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Cascader } from 'antd';
import type { GetProp, CascaderProps } from 'antd';
import type { CascaderProps, GetProp } from 'antd';
import type { SingleCascaderProps } from 'antd/es/cascader';

type DefaultOptionType = GetProp<CascaderProps, 'options'>[number];

Expand Down Expand Up @@ -51,7 +52,7 @@ const options: Option[] = [
},
];

const onChange = (value: string[], selectedOptions: Option[]) => {
const onChange: SingleCascaderProps<Option>['onChange'] = (value, selectedOptions) => {
console.log(value, selectedOptions);
};

Expand Down
3 changes: 2 additions & 1 deletion components/cascader/demo/showCheckedStrategy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Cascader } from 'antd';
import type { MultipleCascaderProps } from 'antd/es/cascader';

const { SHOW_CHILD } = Cascader;

Expand Down Expand Up @@ -43,7 +44,7 @@ const options: Option[] = [
];

const App: React.FC = () => {
const onChange = (value: string[][]) => {
const onChange: MultipleCascaderProps<Option>['onChange'] = (value) => {
console.log(value);
};
return (
Expand Down
3 changes: 2 additions & 1 deletion components/cascader/demo/size.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Cascader } from 'antd';
import type { SingleCascaderProps } from 'antd/es/cascader';

interface Option {
value: string;
Expand Down Expand Up @@ -42,7 +43,7 @@ const options: Option[] = [
},
];

const onChange = (value: string[]) => {
const onChange: SingleCascaderProps<Option>['onChange'] = (value) => {
console.log(value);
};

Expand Down
3 changes: 2 additions & 1 deletion components/cascader/demo/suffix.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { SmileOutlined } from '@ant-design/icons';
import { Cascader } from 'antd';
import type { SingleCascaderProps } from 'antd/es/cascader';

interface Option {
value: string;
Expand Down Expand Up @@ -43,7 +44,7 @@ const options: Option[] = [
},
];

const onChange = (value: string[]) => {
const onChange: SingleCascaderProps<Option>['onChange'] = (value) => {
console.log(value);
};

Expand Down
9 changes: 6 additions & 3 deletions components/cascader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ function highlightKeyword(str: string, lowerKeyword: string, prefixCls?: string)
const cells = str
.toLowerCase()
.split(lowerKeyword)
.reduce((list, cur, index) => (index === 0 ? [cur] : [...list, lowerKeyword, cur]), []);
.reduce<string[]>(
(list, cur, index) => (index === 0 ? [cur] : [...list, lowerKeyword, cur]),
[],
);
const fillCells: React.ReactNode[] = [];
let start = 0;

Expand Down Expand Up @@ -102,13 +105,13 @@ const defaultSearchRender: ShowSearchType['render'] = (inputValue, path, prefixC
return optionList;
};

type SingleCascaderProps<OptionType extends BaseOptionType> = Omit<
export type SingleCascaderProps<OptionType extends BaseOptionType = any> = Omit<
RcSingleCascaderProps<OptionType>,
'checkable' | 'options'
> & {
multiple?: false;
};
type MultipleCascaderProps<OptionType extends BaseOptionType> = Omit<
export type MultipleCascaderProps<OptionType extends BaseOptionType = any> = Omit<
RcMultipleCascaderProps<OptionType>,
'checkable' | 'options'
> & {
Expand Down
1 change: 1 addition & 0 deletions components/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const InternalCheckbox: React.ForwardRefRenderFunction<CheckboxRef, CheckboxProp
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
{/* @ts-ignore */}
<RcCheckbox
aria-checked={ariaChecked}
{...checkboxProps}
Expand Down
Loading

0 comments on commit 14a1e6b

Please sign in to comment.