最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

node.js - TypeScript compiler suddenly became more strict - Stack Overflow

matteradmin8PV0评论

I am trying to build a Node.js project from a few years ago and I'm encountering TypeScript compiler issues that were not present back in the days. Although I am using the exact same node version my project fails to build. The GitHub Actions workflows from that time also went through successfully, but also not anymore.

The TS compiler is actually correct with the complaints, but I want to compile it to find the cause of a regression and I don't want to fix hundreds of these new errors.

/Users/user/Desktop/g2d/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
../g2d/src/main.ts(140,40): error TS2571: Object is of type 'unknown'.
../g2d/src/main.ts(199,40): error TS2571: Object is of type 'unknown'.
../g2d/src/main.ts(240,11): error TS2532: Object is possibly 'undefined'.
../g2d/src/main.ts(244,42): error TS2571: Object is of type 'unknown'.
../g2d/src/main.ts(272,42): error TS2571: Object is of type 'unknown'.
../g2d/src/main.ts(307,42): error TS2571: Object is of type 'unknown'.

All dependencies in package.json are locked to its minor version, and I am using the same node version 14.17.6. Can anyone explain me why my project fails with a seamingly more strict setting?

  "engines": {
    "node": "14.17.6"
  },
  "dependencies": {
    "some-dependency": "1.2.3",
    ...
  },
  "dependencies": {
    "ts-node": "10.9.1",
    "typescript": "4.8.2",
    ...
  }

The tsconfig.json looks as follows:

{
  "ts-node": {
    "swc": true
  },
  "compilerOptions": {
    // Basic configuration
    "incremental": true,
    "module": "CommonJS",
    "rootDir": ".",
    "outDir": "dist",
    "sourceMap": true,
    "declaration": true,
    "target": "ES2021",

    // Type checking options
    "strict": false,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "strictFunctionTypes": false,
    "strictPropertyInitialization": false,
    "noImplicitReturns": false,
    "noUncheckedIndexedAccess": false,

    // Code quality options
    "allowUnreachableCode": true,
    "allowUnusedLabels": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,

    // Module resolution
    "resolveJsonModule": true,
    "moduleResolution": "node",
    "esModuleInterop": true,

    // Library definitions
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "ES2021"
    ],

    // Skip unnecessary checks
    "skipLibCheck": true
  },
  "include": [
    "src/**/*.ts",
    "test/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}
Post a comment

comment list (0)

  1. No comments so far