vercel / next.js

The React Framework
https://nextjs.org
MIT License
123.18k stars 26.3k forks source link

Incorrect alternates Example in Metadata Interface Documentation #62909

Open ciruz opened 4 months ago

ciruz commented 4 months ago

Link to the code that reproduces this issue

https://github.com/ciruz/next.js-hreflang

To Reproduce

The metadata-interface.d.ts file contains incorrect documentation regarding the structure of the alternates property within the Metadata type. The example provided uses hreflang to define alternate languages, which contradicts the actual interface definition that expects a languages property.

image

image

image

image

Current vs. Expected behavior

Show a correct example.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 18.18.2
  npm: N/A
  Yarn: N/A
  pnpm: 8.15.4
Relevant Packages:
  next: 14.1.2
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

TypeScript (plugin, built-in types)

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

No response

mrgwd commented 2 months ago

I am facing the same bug,

Code

export const metadata: Metadata = {
  title: 'My website',
  description: 'My awesome website',
  metadataBase: new URL('https://mywebsitecom/images/images/'),
  openGraph: {
    images: '/opengraph-image.jpg',
  },
  alternates: {
    canonical: 'https://example.com',
    hreflang: { 'en-US': 'https://example.com/en-US' },
  },
}

Error

Object literal may only specify known properties, and 'hreflang' does not exist in type 'AlternateURLs'.ts(2353)
metadata-interface.d.ts(196, 5): The expected type comes from property 'alternates' which is declared here on type 'Metadata'

Environment information


Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
Binaries:
  Node: v18.18.0
  npm: 9.8.1
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.3
  eslint-config-next: 14.2.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5
Next.js Config:
  output: 'export'