惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
博客园 - 叶小钗
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
爱范儿
爱范儿
小众软件
小众软件
K
Kaspersky official blog
P
Proofpoint News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
V
Vulnerabilities – Threatpost
博客园_首页
Microsoft Security Blog
Microsoft Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
V
V2EX
C
Check Point Blog
S
Schneier on Security
P
Palo Alto Networks Blog
IT之家
IT之家
GbyAI
GbyAI
T
Threat Research - Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
Project Zero
Project Zero
Y
Y Combinator Blog
V
Visual Studio Blog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
S
Securelist
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理

博客园 - sekihin

【SQLSERVER】备份还原除当前数据库~之外的其他数据库的bak备份 【前端】常用VsCode插件 React席哪个能优化 20 GitHub 仓库帮助你成为 React专家 Export a named export for each HTTP method instead.(Next.js 15) Error occurred prerendering page "/_not-found".(Next.js 15) Error: Attempted to call generateViewport() from the server (Next.js 15) [cause]: TypeError: e_.createContext is not a function (Next.js 15) Cursor - AI代码编辑器的使用指南 Next.js项目中.prettierrc.json的配置 Next.js项目中.eslintrc.js的配置 nvm: Node Version Manager PHP slim 部署Apache NestJS 部署Apache NestJS导出API文档 ChatGPT plugins Obisidian plugins Data Transfer Objects (DTOs) in NestJS TypeError: stringWidth is not a function
Build nest.js by tsconfig.json
sekihin · 2024-12-12 · via 博客园 - sekihin

对比这两个 tsconfig.json 文件,我们可以看到一些关键的差异。让我们逐项分析一下这些差异,并指出可能存在的问题。

修改前的 tsconfig.json

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,  
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "declaration": true,    
    "outDir": "./dist",
    "baseUrl": "./",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,   
    "target": "ES2021",
    "module": "commonjs",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,              
    "removeComments": true,    
    "paths": {
      "@/*": ["./*"]
    }
  }
}

修改后的 tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2021",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false
  }
}

主要差异

  1. 缺少的配置

    • 修改后的版本中删除了以下选项:

      • "lib": ["dom", "dom.iterable", "esnext"]:指定要包含在编译中的库。

      • "allowJs": true:允许编译JavaScript文件。

      • "noEmit": true:不生成输出文件。

      • "resolveJsonModule": true:允许导入JSON模块。

      • "isolatedModules": true:确保每个文件都是单独的模块。

      • "paths": { "@/*": ["./*"] }:配置路径别名。

  2. 影响

    • 编译输出"noEmit": true 的删除使得TypeScript编译器不再阻止生成输出文件,这可能是编译后没有输出的原因。确保你真的需要输出文件时,请不要启用 noEmit

    • JavaScript支持:删除 allowJs 可能会导致编译器忽略任何JavaScript文件。

    • 库引用:删除 lib 配置后,TypeScript可能无法识别某些全局类型,如DOM相关类型。

    • 模块解析resolveJsonModuleisolatedModules 的删除可能影响你如何处理JSON模块和模块解析。

建议

根据需求,调整 tsconfig.json 中的选项。如果你需要输出文件,确保 noEmit 设置为 false 或删除该选项。如果项目中包含JavaScript文件,请启用 allowJs

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,  
    "strict": true,
    "noEmit": false,  // 确保生成输出文件
    "esModuleInterop": true,
    "declaration": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "target": "ES2021",
    "module": "commonjs",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "removeComments": true,
    "paths": {
      "@/*": ["./*"]
    }
  }
}