Skip to content

Commit 1717fd2

Browse files
authored
Fix IntelliSense for generateMetadata (vercel#46624)
Related to vercel#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)
1 parent fcfab17 commit 1717fd2

File tree

3 files changed

+22
-1
lines changed
  • packages/next/src/server/typescript/rules
  • test/e2e/app-dir/metadata/app/type-checking

3 files changed

+22
-1
lines changed

packages/next/src/server/typescript/rules/metadata.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ function updateVirtualFileWithType(
158158
if (ts.isFunctionDeclaration(node)) {
159159
if (isGenerateMetadata) {
160160
nodeEnd = node.body!.getFullStart()
161-
annotation = TYPE_ANOTATION_ASYNC
161+
const isAsync = node.modifiers?.some(
162+
(m) => m.kind === ts.SyntaxKind.AsyncKeyword
163+
)
164+
annotation = isAsync ? TYPE_ANOTATION_ASYNC : TYPE_ANOTATION
162165
} else {
163166
return
164167
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function Page() {
2+
return null
3+
}
4+
5+
export async function generateMetadata() {
6+
return {
7+
title: 'foo',
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function Page() {
2+
return null
3+
}
4+
5+
export function generateMetadata() {
6+
return {
7+
title: 'foo',
8+
}
9+
}

0 commit comments

Comments
 (0)