1

I am running into an issue whereby tsc is insisting on type-checking files in the node_modules folder, resulting in errors such as:

> my-project@0.0.0 build:ts
> tsc --project tsconfig.json

node_modules/mongoose/types/query.d.ts:619:34 - error TS1144: '{' or ';' expected.

619     toConstructor(): typeof Query<ResultType, DocType, THelpers, RawDocType>;
                                     ~

node_modules/mongoose/types/query.d.ts:619:45 - error TS1005: '>' expected.

619     toConstructor(): typeof Query<ResultType, DocType, THelpers, RawDocType>;
                                                ~

node_modules/mongoose/types/query.d.ts:619:77 - error TS1109: Expression expected.

619     toConstructor(): typeof Query<ResultType, DocType, THelpers, RawDocType>;
                                                                                ~

node_modules/mongoose/types/query.d.ts:622:19 - error TS1109: Expression expected.

622     update(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions<DocType> | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;

This has only just started happening and I am trying to work out the cause and the resolution. The skipLibCheck parameter doesn't seem to be having any impact.

My tsconfig.json is as follows:

{
  "compilerOptions": {
    "lib": [
      "es2020"
    ],
    "module": "commonjs",
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "strict": false,
    "target": "es2020",
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true,
    "typeRoots": [
      "node_modules/@types"
    ],
    "outDir": "dist",
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": [
    "src/**/*.ts"
  ],
  "paths": {
    "*": [
      "node_modules/*",
      "src/types/*"
    ]
  },
  "ts-node": {
    "files": true,
  }
}

Version info:

  • tsc 4.5.5 (provided by typescript@4.5.5)
  • node v16.10.0
Andre M
  • 6,649
  • 7
  • 52
  • 93

1 Answers1

0

The issue turned out to be a Typescript version mismatch, where we were using an older version than one of our dependencies.

The project was using Typescript 4.5.5 and one of the dependencies, in this case mongoose, changed to using Typescript 4.8.x in their 6.7.0 release. I didn't catch this until I checked the node_modules/mongoose/package.json and noticed that package.json specified:

"mongoose": "^6.1.2"

This meant the minor version was free to change, since it was an equivalent version, resulting in a silent breaking change appearing in our project.

This means I have two solutions:

  • Upgrade the Typescript version, used by the project
  • Use the '~' for the mongoose version to stay in 6.1.x

The first approach is what makes sense medium to long term, but the second one will get us unblocked the fastest. This is partly because upgrading the TS version will present the risk of unknowns, which we aren't ready for.

Andre M
  • 6,649
  • 7
  • 52
  • 93