typescript - NextJS TypeScript 问题 : randomUUID? ():字符串 - 错误 TS2386:重载签名必须全部是可选或必需的

标签 typescript next.js

我有一个带有 Lerna 的 mono-rep 结构,用于 2 个 NextJS 项目和 1 个共享项目。

最近我尝试启用typescript。 NextJS 项目似乎工作正常(遵循他们的文档),但另一个项目在编译时抛出了问题。

软件包版本:

"next": "^12.0.1",
"typescript": "^4.6.2"

TypeScript 配置 (tsconfig.json):

{
    "compilerOptions": {
        "module": "commonjs",
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "strict": false,
        "target": "es6",
        "noImplicitAny": true,
        "moduleResolution": "node",
        "sourceMap": false,
        "outDir": "dist",
        "allowJs": true,
        "baseUrl": ".",
        "incremental": true,
        "resolveJsonModule": true,
        "isolatedModules": true,
        "jsx": "preserve"
    },
    "exclude": [
        "dist",
        "jest.*.js",
    ]
}

错误:

../../node_modules/next/types/index.d.ts:203:5
error TS2386: Overload signatures must all be optional or required.

203:5     randomUUID?(): string

最佳答案

看起来这个问题将在基于 this PR 的 next.js 版本 12.1.1 中得到修复.

目前,您可以 1) 将 typescript 回滚到 4.5.5,2) 升级到 next.js 的 12.1.1-canary 版本,或者 3) 打开 skipLibCheck正如 jsejcksn 所提到的和 salar-hafezi .

关于typescript - NextJS TypeScript 问题 : randomUUID? ():字符串 - 错误 TS2386:重载签名必须全部是可选或必需的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71361915/

相关文章:

node.js - 在 Azure 应用服务 (Linux) 上运行的 Node/Next/React 应用程序是否需要 web.config 文件?

javascript - Next.js 13 应用程序目录中的动态路由抛出 404 Not Found 错误

node.js - Sequelize `findOne` 工作不如预期

javascript - useSWR 用于多个请求

html - TypeScript 中是否有 HTMLElement 的对象初始值设定项?

angular - 获取枚举值 typescript 的索引

typescript - 续写 TypeScript 中的模型 getter

javascript - 如何在nestjs中执行嵌套路由?

types - 在 TypeScript 中将一个对象属性复制到另一个对象,导致错误 TS2339

html - 中心定位5排网格(附图)