Skip to content

Commit fe9a329

Browse files
authored
refactor: replace any with stricter types (#21477)
* refactor: replace any with stricter types * refactor: simplify ComboButton middleware typing
1 parent e46239c commit fe9a329

4 files changed

Lines changed: 22 additions & 17 deletions

File tree

packages/react/examples/custom-data-table-state-manager-vite/src/hooks/useCollator.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useCallback } from 'react';
22

33
/**
44
* @param {Intl.Collator} collator The ECMA402 collator.
5-
* @returns {(a: any, b: any) => boolean} The comparator.
65
*/
76
const useCollator = (collator) =>
87
useCallback(

packages/react/previewer/codePreviewer.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright IBM Corp. 2025
2+
* Copyright IBM Corp. 2025, 2026
33
*
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
@@ -23,12 +23,21 @@ import {
2323
ThemeScss,
2424
} from './storybookStyles';
2525

26+
type StoryWithSourceCode = {
27+
parameters: {
28+
docs: {
29+
source: {
30+
originalSource: string;
31+
};
32+
};
33+
};
34+
};
35+
2636
export const stackblitzPrefillConfig = (
27-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452
28-
code: any,
37+
code: StoryWithSourceCode,
2938
// components: Array<string>, // Add all required components to be imported from @carbon/react
3039
// icons: Array<string> // Add all required icons to be imported from @carbon/icons-react
31-
customImport: string
40+
customImport?: string
3241
) => {
3342
const storyCode = code.parameters.docs.source.originalSource
3443
.replace(/^\s*args\s*=>\s*{\s*|}\s*;?\s*$/g, '')

packages/react/src/components/Button/Button.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import PropTypes from 'prop-types';
9-
import React from 'react';
9+
import React, { type ReactNode } from 'react';
1010
import { IconButton, IconButtonKind, IconButtonKinds } from '../IconButton';
1111
import { PopoverAlignment } from '../Popover';
1212
import ButtonBase from './ButtonBase';
@@ -125,11 +125,8 @@ export type ButtonProps<T extends React.ElementType> =
125125
PolymorphicComponentPropWithRef<T, ButtonBaseProps>;
126126

127127
export type ButtonComponent = <T extends React.ElementType = 'button'>(
128-
props: ButtonProps<T>,
129-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452
130-
context?: any
131-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452
132-
) => React.ReactElement | any;
128+
props: ButtonProps<T>
129+
) => ReactNode;
133130

134131
function isIconOnlyButton(
135132
hasIconOnly: ButtonBaseProps['hasIconOnly'],

packages/react/src/components/ComboButton/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ import { useId } from '../../internal/useId';
1717
import { usePrefix } from '../../internal/usePrefix';
1818
import useIsomorphicEffect from '../../internal/useIsomorphicEffect';
1919
import {
20-
useFloating,
20+
autoUpdate,
2121
flip,
22-
hide,
2322
size as floatingSize,
24-
autoUpdate,
23+
hide,
24+
useFloating,
25+
type Middleware,
2526
} from '@floating-ui/react';
2627
import { useFeatureFlag } from '../FeatureFlags';
2728
import { mergeRefs } from '../../tools/mergeRefs';
@@ -113,11 +114,10 @@ const ComboButton = React.forwardRef<HTMLDivElement, ComboButtonProps>(
113114
const id = useId('combobutton');
114115
const prefix = usePrefix();
115116
const containerRef = useRef<HTMLDivElement>(null);
116-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452
117-
let middlewares: any[] = [];
117+
const middlewares: Middleware[] = [];
118118

119119
if (!enableOnlyFloatingStyles) {
120-
middlewares = [flip({ crossAxis: false }), hide()];
120+
middlewares.push(flip({ crossAxis: false }), hide());
121121
}
122122

123123
if (menuAlignment === 'bottom' || menuAlignment === 'top') {

0 commit comments

Comments
 (0)