使用nodejs写ts脚本所需的配置

package.json

{
  "dependencies": {
    "@types/node": "^22.14.0",
    "axios": "^1.8.4",
    "node-fetch": "^3.3.2",
    "nodemailer": "^6.9.16",
    "ts-node": "^10.9.2"
  },
  "type": "module",
  "devDependencies": {
    "@types/axios": "^0.14.4",
    "typescript": "^5.8.2"
  }
}

tsconfig.json

{
  "compilerOptions": {
    /* 基础配置 */
    "target": "ES2022",               // 使用现代 ES 标准(匹配 Node.js 18+)
    "module": "NodeNext",             // 使用 Node.js 的模块解析方式
    "moduleResolution": "NodeNext",   // 明确指定 Node 模块解析策略

    /* 类型检查增强 */
    "strict": true,                   // 开启所有严格类型检查
    "noImplicitAny": true,            // 禁止隐式 any 类型
    "strictNullChecks": true,         // 严格的 null/undefined 检查
    "strictBindCallApply": true,      // 严格检查 bind/call/apply
    "strictFunctionTypes": true,      // 严格函数类型检查
    
    /* 模块处理 */
    "esModuleInterop": true,          // 改进 CommonJS/ESM 互操作性
    "resolveJsonModule": true,        // 允许导入 JSON 文件
    "allowSyntheticDefaultImports": true, // 允许 CJS 模块的默认导入
    
    /* 源码映射 */
    "sourceMap": true,                // 生成 sourcemap
    "inlineSources": true,            // 将源码嵌入 sourcemap
    
    /* 实验性特性 */
    "experimentalDecorators": true,   // 启用装饰器(如需使用装饰器)
    "emitDecoratorMetadata": true,    // 生成装饰器元数据
    
    /* 路径别名 */
    "baseUrl": ".",                   // 基准路径
    "paths": {
      "@/*": ["src/*"]                // 路径映射配置
    }
  },

  //不可或缺,少了会报错无法识别.ts文件
  "ts-node": {
      // Tell ts-node CLI to install the --loader automatically, explained below
      "esm": true
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值