TypeScript version of the Next.js Link and Material UI Link/Button (v5) with forwardRef can be found at https://gist.github.com/kachar/028b6994eb6b160e2475c1bb03e33e6a
Adding some of the components here for brevity
import React, { forwardRef, Ref } from 'react'
import Link, { LinkProps } from 'next/link'
import { Button, ButtonProps } from '@mui/material'
type LinkRef = HTMLButtonElement
type NextLinkProps = Omit<ButtonProps, 'href'> &
Pick<LinkProps, 'href' | 'as' | 'prefetch' | 'locale'>
const LinkButton = ({ href, as, prefetch, locale, ...props }: LinkProps, ref: Ref<LinkRef>) => (
<Link href={href} as={as} prefetch={prefetch} locale={locale} passHref>
<Button ref={ref} {...props} />
</Link>
)
export default forwardRef<LinkRef, NextLinkProps>(LinkButton)
import React from "react";
import { Link as LinkMUI, LinkProps as LinkMUIProps } from "@mui/material";
import NextLink, { LinkProps as NextLinkProps } from "next/link";
export type LinkProps = Omit<LinkMUIProps, "href" | "classes"> &
Pick<NextLinkProps, "href" | "as" | "prefetch">;
export const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(
({ href, as, prefetch, ...props }, ref) => (
<NextLink href={href} as={as} prefetch={prefetch} passHref>
<LinkMUI ref={ref} {...props} />
</NextLink>
)
);