Skip to content

Commit

Permalink
types(vercel#42003): better typing for next/link
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Oct 29, 2022
1 parent d510204 commit 5b6ab92
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions packages/next/client/link.tsx
Expand Up @@ -82,21 +82,18 @@ type InternalLinkProps = {
* @see https://github.com/vercel/next.js/commit/489e65ed98544e69b0afd7e0cfc3f9f6c2b803b7
*/
legacyBehavior?: boolean
// e: any because as it would otherwise overlap with existing types
/**
* Optional event handler for when the mouse pointer is moved onto Link
*/
onMouseEnter?: (e: any) => void
// e: any because as it would otherwise overlap with existing types
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>
/**
* Optional event handler for when Link is touched.
*/
onTouchStart?: (e: any) => void
// e: any because as it would otherwise overlap with existing types
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>
/**
* Optional event handler for when Link is clicked.
*/
onClick?: (e: any) => void
onClick?: React.MouseEventHandler<HTMLAnchorElement>
}

// TODO-APP: Include the full set of Anchor props
Expand Down Expand Up @@ -459,14 +456,14 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
}, [as, href, isVisible, locale, p, router])

const childProps: {
onTouchStart: React.TouchEventHandler
onMouseEnter: React.MouseEventHandler
onClick: React.MouseEventHandler
onTouchStart: React.TouchEventHandler<HTMLAnchorElement>
onMouseEnter: React.MouseEventHandler<HTMLAnchorElement>
onClick: React.MouseEventHandler<HTMLAnchorElement>
href?: string
ref?: any
} = {
ref: setRef,
onClick: (e: React.MouseEvent) => {
onClick: (e) => {
if (process.env.NODE_ENV !== 'production') {
if (!e) {
throw new Error(
Expand Down Expand Up @@ -500,7 +497,7 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
)
}
},
onMouseEnter: (e: React.MouseEvent) => {
onMouseEnter: (e) => {
if (!legacyBehavior && typeof onMouseEnter === 'function') {
onMouseEnter(e)
}
Expand All @@ -519,7 +516,7 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
}
}
},
onTouchStart: (e: React.TouchEvent<HTMLAnchorElement>) => {
onTouchStart: (e) => {
if (!legacyBehavior && typeof onTouchStart === 'function') {
onTouchStart(e)
}
Expand Down

0 comments on commit 5b6ab92

Please sign in to comment.