Ben*_*Ben 14 typescript next.js
使用 Next.JS 检查 TypeScript 错误的唯一方法是使用npm run build
(或yarn build
)。
如果你运行npm run dev
,它不会显示 TypeScript 错误,这很糟糕,因为在开发时在终端窗口中看到它们会更好。
有什么办法可以让npm run dev
显示TS错误吗?
仅供参考 - 我真的不喜欢使用我的 IDE 来处理 TS 错误。只是我个人的喜好。我更喜欢在终端窗口中看到它们以及所有其他错误。
brc*_*-dd 13
如果您使用 TS4+,您可以执行以下操作:
// package.json
{
"scripts": {
"dev": "next dev",
"dev:ts": "yarn dev & yarn ts:watch", // <-- or use concurrently here
// npmjs.com/package/concurrently
"ts": "tsc --noEmit --incremental",
"ts:watch": "yarn ts --watch"
},
// ...
}
Run Code Online (Sandbox Code Playgroud)
您还可以提供自定义 webpack 配置,如下所示:
// package.json
{
"scripts": {
"dev": "next dev",
"dev:ts": "yarn dev & yarn ts:watch", // <-- or use concurrently here
// npmjs.com/package/concurrently
"ts": "tsc --noEmit --incremental",
"ts:watch": "yarn ts --watch"
},
// ...
}
Run Code Online (Sandbox Code Playgroud)
此处正在跟踪功能请求。
归档时间: |
|
查看次数: |
7759 次 |
最近记录: |