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

Missing types for Link attributes onClick, onTouchStart, onMouseEnter on Next.js 13 #42003

Closed
1 task done
nbouvrette opened this issue Oct 27, 2022 · 1 comment · Fixed by #42117
Closed
1 task done
Labels
bug Issue was opened via the bug report template. TypeScript Related to types with Next.js.

Comments

@nbouvrette
Copy link
Contributor

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

When updating to Next.js 13, I had to move onClick, onTouchStart, onMouseEnter directly to the Link component and noticed that the event type in /next/dist/client/link.d.ts was set to any

What browser are you using? (if relevant)

N/A

How are you deploying your application? (if relevant)

N/A

Describe the Bug

I'm getting an Unsafe member access .preventDefault on an 'any' value. when using the current Next.js 13 types.

A workaround is to cast the type like this: onClick={(event: MouseEvent) => {}}

Looking at

// e: any because as it would otherwise overlap with existing types
it says it would overlap with existing type? I'm not sure I understand why

I would do a PR myself but I am not familiar with the process

Expected Behavior

I would expect the following event types:

    onMouseEnter?: (e: React.MouseEvent<HTMLAnchorElement>) => void;
    onTouchStart?: (e: React.TouchEvent<HTMLAnchorElement>) => void;
    onClick?: (e: React.MouseEvent<HTMLAnchorElement>) => void;

Link to reproduction

// e: any because as it would otherwise overlap with existing types

To Reproduce

Just use onClick and then try to use the event argument like this:

 <Link onClick={(event) => { event.preventDefault() }}></Link>
@nbouvrette nbouvrette added the bug Issue was opened via the bug report template. label Oct 27, 2022
@balazsorban44 balazsorban44 added the TypeScript Related to types with Next.js. label Oct 27, 2022
SukkaW added a commit to SukkaW/next.js that referenced this issue Oct 29, 2022
SukkaW added a commit to SukkaW/next.js that referenced this issue Nov 1, 2022
SukkaW added a commit to SukkaW/next.js that referenced this issue Nov 2, 2022
SukkaW added a commit to SukkaW/next.js that referenced this issue Nov 2, 2022
ijjk pushed a commit that referenced this issue Nov 14, 2022
<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

The PR closes #42003.

Replace `(e: any) => void` with
`React.MouseEventHandler<HTMLAnchorElement>` and
`React.TouchEventHandler<HTMLAnchorElement>`. The original typing
overlap issue has also been fixed.

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. TypeScript Related to types with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants