Explorar el Código

fix: ts type check error which cause by ts version update

pointhalo hace 2 años
padre
commit
75beea605c

+ 4 - 4
packages/semi-foundation/overflowList/foundation.ts

@@ -8,7 +8,7 @@ export interface OverflowListAdapter extends DefaultAdapter {
     updateStates: (state: any) => void;
     updateVisibleState: (visible: Map<string, boolean>) => void;
     notifyIntersect: (res: any) => void;
-    getItemSizeMap: ()=>Map<string, number>
+    getItemSizeMap: () => Map<string, number>
 }
 
 class OverflowListFoundation extends BaseFoundation<OverflowListAdapter> {
@@ -46,7 +46,7 @@ class OverflowListFoundation extends BaseFoundation<OverflowListAdapter> {
 
         const res = {};
         entries.forEach(entry => {
-            const itemKey = get(entry, 'target.dataset.scrollkey');
+            const itemKey: string = get(entry, 'target.dataset.scrollkey');
             const visible = entry.isIntersecting;
             res[itemKey] = entry;
             visibleState.set(itemKey, visible);
@@ -77,7 +77,7 @@ class OverflowListFoundation extends BaseFoundation<OverflowListAdapter> {
         const { items } = this.getProps();
         return cloneDeep(items).reverse();
     }
-    handleCollapseOverflow(){
+    handleCollapseOverflow() {
         const { minVisibleItems, collapseFrom } = this.getProps();
         const { overflowWidth, containerWidth, pivot: statePivot, overflowStatus } = this.getStates();
         const { items, onOverflow } = this.getProps();
@@ -114,7 +114,7 @@ class OverflowListFoundation extends BaseFoundation<OverflowListAdapter> {
                 overflow,
             });
             // trigger onOverflow
-            if (statePivot !== pivot){
+            if (statePivot !== pivot) {
                 onOverflow(overflow);
             }
             return;

+ 1 - 0
packages/semi-foundation/table/foundation.ts

@@ -465,6 +465,7 @@ class TableFoundation<RecordType> extends BaseFoundation<TableAdapter<RecordType
                                             }
                                             return arr;
                                         },
+                                        // @ts-ignore
                                         [...children]
                                     ),
                                 });

+ 4 - 3
packages/semi-ui/datePicker/datePicker.tsx

@@ -16,6 +16,7 @@ import DatePickerFoundation, {
     Type,
     RangeType
 } from '@douyinfe/semi-foundation/datePicker/foundation';
+import MonthGridFoundation from '@douyinfe/semi-foundation/datePicker/monthsGridFoundation';
 import { cssClasses, strings, numbers } from '@douyinfe/semi-foundation/datePicker/constants';
 import { strings as popoverStrings, numbers as popoverNumbers } from '@douyinfe/semi-foundation/popover/constants';
 import BaseComponent from '../_base/baseComponent';
@@ -579,7 +580,7 @@ export default class DatePicker extends BaseComponent<DatePickerProps, DatePicke
             defaultPickerValue
         };
 
-        return insetInput ? <DateInput {...props} insetInput={insetInput} /> : null;
+        return insetInput ? <DateInput {...props} insetInput={insetInput}/> : null;
     }
 
     handleOpenPanel = () => this.foundation.openPanel();
@@ -602,7 +603,7 @@ export default class DatePicker extends BaseComponent<DatePickerProps, DatePicke
         }
     };
     handleInsetDateFocus = (e: React.FocusEvent, rangeType: 'rangeStart' | 'rangeEnd') => {
-        const monthGridFoundation = get(this, 'monthGrid.current.foundation');
+        const monthGridFoundation = get(this, 'monthGrid.current.foundation') as MonthGridFoundation;
         if (monthGridFoundation) {
             monthGridFoundation.showDatePanel(strings.PANEL_TYPE_LEFT);
             monthGridFoundation.showDatePanel(strings.PANEL_TYPE_RIGHT);
@@ -611,7 +612,7 @@ export default class DatePicker extends BaseComponent<DatePickerProps, DatePicke
     }
 
     handleInsetTimeFocus = () => {
-        const monthGridFoundation = get(this, 'monthGrid.current.foundation');
+        const monthGridFoundation = get(this, 'monthGrid.current.foundation') as MonthGridFoundation;
         if (monthGridFoundation) {
             monthGridFoundation.showTimePicker(strings.PANEL_TYPE_LEFT);
             monthGridFoundation.showTimePicker(strings.PANEL_TYPE_RIGHT);

+ 2 - 1
packages/semi-ui/input/textarea.tsx

@@ -20,7 +20,8 @@ type OmitTextareaAttr =
     | 'onBlur'
     | 'onKeyDown'
     | 'onKeyPress'
-    | 'onKeyUp';
+    | 'onKeyUp'
+    | 'onResize'
 
 export interface TextAreaProps extends
     Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, OmitTextareaAttr> {

+ 2 - 2
packages/semi-ui/navigation/index.tsx

@@ -44,6 +44,7 @@ export type NavItems = (string | SubNavPropsWithItems | NavItemPropsWithItems)[]
 export interface NavProps extends BaseProps {
     bodyStyle?: React.CSSProperties;
     children?: React.ReactNode;
+    
     defaultIsCollapsed?: boolean;
     defaultOpenKeys?: React.ReactText[];
     defaultSelectedKeys?: React.ReactText[];
@@ -264,7 +265,7 @@ class Nav extends BaseComponent<NavProps, NavState> {
      * @returns {JSX.Element}
      */
     renderItems(items: (SubNavPropsWithItems | NavItemPropsWithItems)[] = [], level = 0) {
-        const { expandIcon, collapseIcon } = this.props;
+        const { expandIcon } = this.props;
         const finalDom = (
             <>
                 {items.map((item, idx) => {
@@ -275,7 +276,6 @@ class Nav extends BaseComponent<NavProps, NavState> {
                                 {...item as SubNavPropsWithItems}
                                 level={level}
                                 expandIcon={expandIcon}
-                                collapseIcon={collapseIcon}
                             >
                                 {this.renderItems(item.items as (SubNavPropsWithItems | NavItemPropsWithItems)[], level + 1)}
                             </SubNav>

+ 7 - 6
packages/semi-ui/table/Body/index.tsx

@@ -31,9 +31,10 @@ import SectionRow from './SectionRow';
 import TableHeader from '../TableHeader';
 import ConfigContext from '../../configProvider/context';
 import TableContext, { TableContextProps } from '../table-context';
-import {
+import type {
     ExpandedRowRender,
     Virtualized,
+    VirtualizedItemSize,
     GetVirtualizedListRef,
     ColumnProps,
     Size,
@@ -253,9 +254,9 @@ class Body extends BaseComponent<BodyProps, BodyState> {
         const virtualizedItem = get(virtualizedData, index);
         const defaultConfig = getDefaultVirtualizedRowConfig(tableSize, virtualizedItem.sectionRow);
 
-        const itemSize = get(virtualized, 'itemSize', defaultConfig.height);
+        const itemSize = get(virtualized, 'itemSize', defaultConfig.height) as VirtualizedItemSize;
 
-        let realSize = itemSize;
+        let realSize = itemSize as number;
 
         if (typeof itemSize === 'function') {
             realSize = itemSize(index, {
@@ -279,7 +280,7 @@ class Body extends BaseComponent<BodyProps, BodyState> {
     };
 
     handleVirtualizedScroll = (props = {}) => {
-        const onScroll = get(this.props.virtualized, 'onScroll');
+        const onScroll: undefined | ((props?: any) => void) = get(this.props.virtualized, 'onScroll');
         if (typeof onScroll === 'function') {
             onScroll(props);
         }
@@ -760,8 +761,8 @@ class Body extends BaseComponent<BodyProps, BodyState> {
         const tableStyle: {
             width?: string | number
         } = {};
-        const Table = get(components, 'body.outer', 'table');
-        const BodyWrapper = get(components, 'body.wrapper') || 'tbody';
+        const Table = get(components, 'body.outer', 'table') as unknown as typeof React.Component;
+        const BodyWrapper = (get(components, 'body.wrapper') || 'tbody') as unknown as typeof React.Component;
 
         if (y) {
             bodyStyle.maxHeight = y;

+ 1 - 1
packages/semi-ui/table/HeadTable.tsx

@@ -78,7 +78,7 @@ class HeadTable extends React.PureComponent<HeadTableProps> {
             return null;
         }
 
-        const Table = get(components, 'header.outer', 'table');
+        const Table = get(components, 'header.outer', 'table') as unknown as typeof React.Component;
         const x = get(scroll, 'x');
         const headStyle: Partial<React.CSSProperties> = {};
         const tableStyle: { width?: number | string } = {};

+ 4 - 4
packages/semi-ui/table/ResizableTable.tsx

@@ -14,15 +14,15 @@ import Table from './Table';
 import { cloneDeep, mergeColumns } from './utils';
 import getColumns from './getColumns';
 import ResizableHeaderCell from './ResizableHeaderCell';
-import { TableProps, ColumnProps } from './interface';
+import type { ResizableProps, TableProps, ColumnProps } from './interface';
 
 const ResizableTable = (props: TableProps = {}, ref: React.MutableRefObject<Table<any>> | ((instance: Table<any>) => void)) => {
     const { components: propComponents, columns: propColumns, resizable, ...restProps } = props;
 
     const childrenColumnName = 'children';
-    const onResize = get(resizable, 'onResize', noop);
-    const onResizeStart = get(resizable, 'onResizeStart', noop);
-    const onResizeStop = get(resizable, 'onResizeStop', noop);
+    const onResize = get(resizable, 'onResize', noop) as ResizableProps<any>['onResize'];
+    const onResizeStart = get(resizable, 'onResizeStart', noop) as ResizableProps<any>['onResize'];
+    const onResizeStop = get(resizable, 'onResizeStop', noop) as ResizableProps<any>['onResize'];
 
     /**
      * 此处关于 columns 有三个存储

+ 2 - 0
packages/semi-ui/table/TableHeaderRow.tsx

@@ -190,6 +190,7 @@ export default class TableHeaderRow extends BaseComponent<TableHeaderRowProps, R
             }
 
             return (
+                // @ts-ignore  no need to do complex ts type checking and qualification
                 <HeaderCell
                     role="columnheader"
                     aria-colindex={cellIndex + 1}
@@ -201,6 +202,7 @@ export default class TableHeaderRow extends BaseComponent<TableHeaderRowProps, R
         });
 
         return (
+            // @ts-ignore no need to do complex ts type checking and qualification
             <HeaderRow
                 role="row"
                 aria-rowindex={index + 1}

+ 6 - 1
packages/semi-ui/table/interface.ts

@@ -289,8 +289,13 @@ export type VirtualizedOnScrollArgs = {
     scrollOffset?: number;
     scrollUpdateWasRequested?: boolean
 };
+
+export type VirtualizeItemSizeRow = { 
+    sectionRow?: boolean; 
+    expandedRow?: boolean
+};
 export type VirtualizedMode = 'list' | 'grid';
-export type VirtualizedItemSizeFn = (index?: number) => number;
+export type VirtualizedItemSizeFn = (index?: number, row?: VirtualizeItemSizeRow) => number;
 export type VirtualizedItemSize = number | VirtualizedItemSizeFn;
 export type VirtualizedOnScroll = (object: VirtualizedOnScrollArgs) => void;
 export interface VirtualizedProps {

+ 2 - 2
packages/semi-ui/tooltip/index.tsx

@@ -719,7 +719,7 @@ export default class Tooltip extends BaseComponent<TooltipProps, TooltipState> {
         const { isInsert, triggerEventSet, visible, id } = this.state;
         const { wrapWhenSpecial, role, trigger } = this.props;
         let { children } = this.props;
-        const childrenStyle = { ...get(children, 'props.style') };
+        const childrenStyle = { ...get(children, 'props.style') as React.CSSProperties } ;
         const extraStyle: React.CSSProperties = {};
 
         if (wrapWhenSpecial) {
@@ -762,7 +762,7 @@ export default class Tooltip extends BaseComponent<TooltipProps, TooltipState> {
             ...(children as React.ReactElement).props,
             ...this.mergeEvents((children as React.ReactElement).props, triggerEventSet),
             style: {
-                ...get(children, 'props.style'),
+                ...get(children, 'props.style') as React.CSSProperties,
                 ...extraStyle,
             },
             className: classNames(