next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Type error: PageComponent/LayoutComponent is declared but never used

Open richardkall opened this issue 1 year ago • 2 comments

Verify canary release

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

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000
Binaries:
  Node: 16.17.0
  npm: 8.15.0
  Yarn: 1.22.19
  pnpm: N/A
Relevant packages:
  next: 13.0.0
  eslint-config-next: 13.0.0
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

When adding "noUnusedLocals": true to tsconfig.json and running a type-check with npx tsc (or next build), it fails due to declared but unused types:

.next/types/app/layout.ts:17:6 - error TS6196: 'PageComponent' is declared but never used.

17 type PageComponent = (props: PageProps) => React.ReactNode | Promise<React.ReactNode>
        ~~~~~~~~~~~~~

.next/types/app/page.ts:18:6 - error TS6196: 'LayoutComponent' is declared but never used.

18 type LayoutComponent = (props: LayoutProps) => React.ReactNode | Promise<React.ReactNode>
        ~~~~~~~~~~~~~~~

Expected Behavior

No type errors.

Link to reproduction

https://github.com/richardkall/next-bug-repro

To Reproduce

  1. Clone repo.
  2. Run npm install
  3. Run npm run build

richardkall avatar Oct 26 '22 21:10 richardkall

Was able to solve this adding ".next" to the "exclude" arrray on tsconfig.json.

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "baseUrl": "./",
    "paths": {
      "tina-types": [
        ".tina/__generated__/types.ts"
      ],
      "tina-client": [
        ".tina/__generated__/client"
      ]
    },
    "plugins": [
      {
        "name": "next"
      }
    ]
  },
  "include": [
    "**/*.ts",
    "**/*.tsx",
    "next-env.d.ts",
    ".next/types/**/*.ts",
    ".tina/__generated__/types.ts",
    ".tina/config.tsx"
  ],
  "exclude": [
    "node_modules",
    ".next",
  ]
}

brvnonascimento avatar Oct 28 '22 19:10 brvnonascimento

Confirming the problem and the solution above:

Was able to solve this adding ".next" to the "exclude" array on tsconfig.json.

https://github.com/vercel/next.js/issues/41901#issuecomment-1295404567

kreempuff avatar Nov 16 '22 17:11 kreempuff

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[bot] avatar Dec 23 '22 00:12 github-actions[bot]