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

[NEXT-665] TypeScript error when using generateMetadata() in WebStorm IDE #46431

Closed
1 task done
patrykszwed opened this issue Feb 25, 2023 · 3 comments
Closed
1 task done
Assignees
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. TypeScript Related to types with Next.js.

Comments

@patrykszwed
Copy link

patrykszwed commented Feb 25, 2023

Verify canary release

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

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 18.13.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 13.2.2-canary.1
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Metadata (metadata, generateMetadata, next/head, head.js), TypeScript

Link to the code that reproduces this issue

https://github.com/patrykszwed/next-metadata-ts-error

To Reproduce

  1. Run npx create-next-app --example reproduction-template-app-dir reproduction-app
  2. Add generateMetadata function to page.tsx at a root level. That code should be enough:
export async function generateMetadata() {
  return {};
}

export default function Home() {
  return null
}

Describe the Bug

When implementing a generateMetadata function and opening a project in WebStorm, a TypeScript error is shown at a line where the function is defined. The error says: TS1055: Type 'Metadata | Promise ' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.

However, building the project works fine. Moreover, when opening the same project in Visual Studio Code, there are no errors at all.

WebStorm:
image

Visual Studio Code:
image

Expected Behavior

No TypeScript errors are shown when defining a valid generateMetadata function.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-665

@patrykszwed patrykszwed added the bug Issue was opened via the bug report template. label Feb 25, 2023
@github-actions github-actions bot added the TypeScript Related to types with Next.js. label Feb 25, 2023
@shuding shuding self-assigned this Feb 26, 2023
@timneutkens timneutkens added the linear: next Confirmed issue that is tracked by the Next.js team. label Feb 27, 2023
@timneutkens timneutkens changed the title TypeScript error when using generateMetadata() in WebStorm IDE [NEXT-665] TypeScript error when using generateMetadata() in WebStorm IDE Feb 27, 2023
@t3dotgg
Copy link

t3dotgg commented Mar 1, 2023

Confirming this isn't Webstorm specific, appears these typedefs are bad
image

https://github.com/vercel/next.js/pull/45723/files#r1121140364

@ijjk
Copy link
Member

ijjk commented Mar 1, 2023

This should be fixed by #46596 which is now available in v13.3.3-canary.0

@ijjk ijjk closed this as completed Mar 1, 2023
kodiakhq bot pushed a commit that referenced this issue Mar 1, 2023
Related to #46431, this makes sure the IntelliSense for both sync and async `generateMetadata` is correct.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.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 Mar 31, 2023
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. linear: next Confirmed issue that is tracked by the Next.js team. TypeScript Related to types with Next.js.
Projects
None yet
Development

No branches or pull requests

5 participants