Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui] Change React.ReactElement<any> to React.ReactElement<unknown> #43402

Merged
merged 20 commits into from
Oct 3, 2024
2 changes: 1 addition & 1 deletion docs/data/material/components/app-bar/BackToTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface Props {
* You won't need it on your project.
*/
window?: () => Window;
children?: React.ReactElement<any>;
children?: React.ReactElement<unknown>;
}

function ScrollTop(props: Props) {
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/app-bar/ElevateAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Props {
* You won't need it on your project.
*/
window?: () => Window;
children?: React.ReactElement<any>;
children?: React.ReactElement<unknown & { elevation?: number }>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is & { elevation?: number } needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here elevation prop is added to children, since unknown type doesn't have elevation type, i explicitly added. I'm not entirely sure if this is optimal, but please let me know if you have better suggestion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can have only the elevation prop:

Suggested change
children?: React.ReactElement<unknown & { elevation?: number }>;
children?: React.ReactElement<{ elevation?: number }>;

As unknown is absorbed in intersections:

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type:~:text=//%20In%20an%20intersection%20everything%20absorbs%20unknown

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed here 3ff9828

}

function ElevationScroll(props: Props) {
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/app-bar/HideAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Props {
* You won't need it on your project.
*/
window?: () => Window;
children?: React.ReactElement<any>;
children?: React.ReactElement<unknown>;
}

function HideOnScroll(props: Props) {
Expand Down
12 changes: 8 additions & 4 deletions docs/data/material/components/autocomplete/Virtualize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ const ListboxComponent = React.forwardRef<
React.HTMLAttributes<HTMLElement>
>(function ListboxComponent(props, ref) {
const { children, ...other } = props;
const itemData: React.ReactElement<any>[] = [];
(children as React.ReactElement<any>[]).forEach(
(item: React.ReactElement<any> & { children?: React.ReactElement<any>[] }) => {
const itemData: React.ReactElement<unknown>[] = [];
(children as React.ReactElement<unknown>[]).forEach(
(
item: React.ReactElement<unknown> & {
children?: React.ReactElement<unknown>[];
},
) => {
itemData.push(item);
itemData.push(...(item.children || []));
},
Expand All @@ -73,7 +77,7 @@ const ListboxComponent = React.forwardRef<
const itemCount = itemData.length;
const itemSize = smUp ? 36 : 48;

const getChildSize = (child: React.ReactElement<any>) => {
const getChildSize = (child: React.ReactElement<unknown>) => {
if (child.hasOwnProperty('group')) {
return 48;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/dialogs/FullScreenDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { TransitionProps } from '@mui/material/transitions';

const Transition = React.forwardRef(function Transition(
props: TransitionProps & {
children: React.ReactElement<any>;
children: React.ReactElement<unknown>;
},
ref: React.Ref<unknown>,
) {
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/lists/InteractiveList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Typography from '@mui/material/Typography';
import FolderIcon from '@mui/icons-material/Folder';
import DeleteIcon from '@mui/icons-material/Delete';

function generate(element: React.ReactElement<any>) {
function generate(element: React.ReactElement<unknown>) {
return [0, 1, 2].map((value) =>
React.cloneElement(element, {
key: value,
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/popper/SpringPopper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Popper from '@mui/material/Popper';
import { useSpring, animated } from '@react-spring/web';

interface FadeProps {
children?: React.ReactElement<any>;
children?: React.ReactElement<unknown>;
in?: boolean;
onEnter?: () => void;
onExited?: () => void;
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/rating/RadioGroupRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const StyledRating = styled(Rating)(({ theme }) => ({

const customIcons: {
[index: string]: {
icon: React.ReactElement<any>;
icon: React.ReactElement<unknown>;
label: string;
};
} = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const ColorlibStepIconRoot = styled('div')<{
function ColorlibStepIcon(props: StepIconProps) {
const { active, completed, className } = props;

const icons: { [index: string]: React.ReactElement<any> } = {
const icons: { [index: string]: React.ReactElement<unknown> } = {
1: <SettingsIcon />,
2: <GroupAddIcon />,
3: <VideoLabelIcon />,
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/integrations/routing/ListRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Router(props: { children?: React.ReactNode }) {
}

interface ListItemLinkProps {
icon?: React.ReactElement<any>;
icon?: React.ReactElement<unknown>;
primary: string;
to: string;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/about/HowToSupport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Widget({
}: {
children: React.ReactNode;
title: string;
icon: React.ReactElement<any>;
icon: React.ReactElement<unknown>;
}) {
return (
<Paper
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/header/HeaderNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const PRODUCT_IDS = [
];

type ProductSubMenuProps = {
icon: React.ReactElement<any>;
icon: React.ReactElement<unknown>;
name: React.ReactNode;
description: React.ReactNode;
chip?: React.ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/home/MaterialDesignComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function Demo({
}: {
name: string;
theme: Theme | undefined;
children: React.ReactElement<any>;
children: React.ReactElement<unknown>;
control?: { prop: string; values: Array<string>; defaultValue?: string };
}) {
const [propValue, setPropValue] = React.useState(
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/home/UserFeedbacks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function Feedback({
avatarSrcSet: string;
name: string;
role: string;
company?: React.ReactElement<any>;
company?: React.ReactElement<unknown>;
};
}) {
return (
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/pricing/PricingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ function RowHead({
children,
startIcon,
...props
}: BoxProps & { startIcon?: React.ReactElement<any> }) {
}: BoxProps & { startIcon?: React.ReactElement<unknown> }) {
return (
<Box
{...props}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/productX/XRoadmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function RoadmapStatusDot({ color }: RoadmapStatusDotProps) {
}

export default function XRoadmap() {
function renderList(content: React.ReactElement<any>, nested?: boolean) {
function renderList(content: React.ReactElement<unknown>, nested?: boolean) {
return (
<Box
sx={{
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/showcase/ViewToggleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const views = ['quilt', 'module', 'agenda', 'week', 'sidebar'] as const;

type View = (typeof views)[number];

const viewIcons: Record<View, React.ReactElement<any>> = {
const viewIcons: Record<View, React.ReactElement<unknown>> = {
quilt: <ViewQuiltRounded />,
module: <ViewModuleRounded />,
agenda: <ViewAgendaRounded />,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/typography/SectionHeadline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function SectionHeadline(props: SectionHeadlineProps) {
) : (
React.cloneElement(title, {
style: {
maxWidth: 500,
maxWidth: '500',
DiegoAndai marked this conversation as resolved.
Show resolved Hide resolved
...(alwaysCenter && {
maxWidth: '100%',
textAlign: 'center',
Expand Down
4 changes: 2 additions & 2 deletions docs/src/layouts/HeroContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { alpha } from '@mui/material/styles';
interface HeroContainerProps {
disableMobileHidden?: boolean;
disableTabExclusion?: boolean;
left: React.ReactElement<any>;
left: React.ReactElement<unknown>;
linearGradient?: boolean;
right: React.ReactElement<any>;
right: React.ReactElement<unknown>;
rightSx?: BoxProps['sx'];
}

Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/JoyUsageDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ interface JoyUsageDemoProps<ComponentProps> {
* A function to override the code block result.
*/
getCodeBlock?: (code: string, props: ComponentProps) => string;
renderDemo: (props: ComponentProps) => React.ReactElement<any>;
renderDemo: (props: ComponentProps) => React.ReactElement<unknown>;
}

export default function JoyUsageDemo<T extends { [k: string]: any } = {}>({
Expand Down
4 changes: 2 additions & 2 deletions docs/src/modules/components/JoyVariablesDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function formatSx(sx: { [k: string]: string | number }) {
interface SlotVariablesProps {
slot: string;
data: Array<DataItem>;
renderField: (item: DataItem) => React.ReactElement<any>;
renderField: (item: DataItem) => React.ReactElement<unknown>;
defaultOpen?: boolean;
}

Expand Down Expand Up @@ -83,7 +83,7 @@ export default function JoyVariablesDemo(props: {
componentName: string;
childrenAccepted?: boolean;
data: Array<DataItem | [string, Array<DataItem>, { defaultOpen?: boolean } | undefined]>;
renderDemo: (sx: { [k: string]: string | number }) => React.ReactElement<any>;
renderDemo: (sx: { [k: string]: string | number }) => React.ReactElement<unknown>;
renderCode?: (formattedSx: string) => string;
}) {
const { componentName, data = [], childrenAccepted = false, renderCode } = props;
Expand Down
2 changes: 1 addition & 1 deletion docs/types/docs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ declare module 'docs/src/modules/components/HighlightedCode' {
component?: React.ElementType;
sx?: object;
}
export default function HighlightedCode(props: Props): React.ReactElement<any>;
export default function HighlightedCode(props: Props): React.ReactElement<unknown>;
}

declare module 'react-imask';
14 changes: 7 additions & 7 deletions packages-internal/test-utils/src/createRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export interface MuiRenderToStringResult {
}

function render(
element: React.ReactElement<any>,
element: React.ReactElement<unknown>,
configuration: ClientRenderConfiguration,
): MuiRenderResult {
const { container, hydrate, wrapper } = configuration;
Expand All @@ -306,7 +306,7 @@ function render(
traceSync('forceUpdate', () =>
testingLibraryRenderResult.rerender(
React.cloneElement(element, {
'data-force-update': String(Math.random()),
['data-force-update' as string]: String(Math.random()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is as string required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here element type is unknown, since unknown doesn't have data-force-update type, i've explicitly marked type as as string

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if I understand correctly, this is casting the key, not the value 🤔

What's the error thrown without the cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of casting, i've tried to fix type error properly here =>09f5298

}),
),
);
Expand All @@ -322,7 +322,7 @@ function render(
}

function renderToString(
element: React.ReactElement<any>,
element: React.ReactElement<unknown>,
configuration: ServerRenderConfiguration,
): { container: HTMLElement; hydrate(): MuiRenderResult } {
const { container, wrapper: Wrapper } = configuration;
Expand Down Expand Up @@ -444,9 +444,9 @@ function createClock(defaultMode: 'fake' | 'real', config: ClockConfig): Clock {

export interface Renderer {
clock: Clock;
render(element: React.ReactElement<any>, options?: RenderOptions): MuiRenderResult;
render(element: React.ReactElement<unknown>, options?: RenderOptions): MuiRenderResult;
renderToString(
element: React.ReactElement<any>,
element: React.ReactElement<unknown>,
options?: RenderOptions,
): MuiRenderToStringResult;
}
Expand Down Expand Up @@ -586,7 +586,7 @@ export function createRenderer(globalOptions: CreateRendererOptions = {}): Rende

return {
clock,
render(element: React.ReactElement<any>, options: RenderOptions = {}) {
render(element: React.ReactElement<unknown>, options: RenderOptions = {}) {
if (!prepared) {
throw new Error(
'Unable to finish setup before `render()` was called. ' +
Expand All @@ -601,7 +601,7 @@ export function createRenderer(globalOptions: CreateRendererOptions = {}): Rende
wrapper: createWrapper(options),
});
},
renderToString(element: React.ReactElement<any>, options: RenderOptions = {}) {
renderToString(element: React.ReactElement<unknown>, options: RenderOptions = {}) {
if (!prepared) {
throw new Error(
'Unable to finish setup before `render()` was called. ' +
Expand Down
Loading