【问题标题】:Prevent tsc type checking projects in node_modules folder?防止 node_modules 文件夹中的 tsc 类型检查项目?
【发布时间】:2022-11-02 05:29:18
【问题描述】:

我遇到了一个问题,tsc 坚持对node_modules 文件夹中的文件进行类型检查,从而导致以下错误:

> 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>;

这才刚刚开始发生,我正在努力找出原因和解决方案。 skipLibCheck 参数似乎没有任何影响。

我的tsconfig.json如下:

{
  "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,
  }
}

版本信息:

  • tsc 4.5.5(由typescript@4.5.5提供)
  • 节点 v16.10.0

【问题讨论】:

    标签: node.js typescript


    【解决方案1】:

    显然,您的 tsconfig.json 文件中缺少 exclude 字段。只需添加:

    "exclude": ["node_modules"]
    

    【讨论】:

      猜你喜欢
      • 2019-11-16
      • 2019-01-09
      • 1970-01-01
      • 2013-08-26
      • 2022-07-21
      • 1970-01-01
      • 2020-02-18
      • 2021-07-16
      • 2015-11-16
      相关资源
      最近更新 更多