【问题标题】:TypeORM throws "Type instantiation is excessively deep and possibly infinite.ts(2589)" error on Repository typingTypeORM 在存储库键入时抛出“类型实例化过深并且可能是无限的.ts(2589)”错误
【发布时间】:2020-01-08 08:58:42
【问题描述】:

更新到VSCode August 2019 (version 1.38) and Typescript 3.6 后,我在TypeORM 存储库初始化时收到了很多Type instantiation is excessively deep and possibly infinite.ts(2589)

import { Connection, Repository, Entity, BaseEntity,  createConnection } from 'typeorm';

@Entity()
class MyEntity extends BaseEntity {
    public id: number;
}

class Test {
    async test() {
        const connection: Connection = await createConnection();
        const myRepo: Repository<MyEntity> = connection.getRepository(MyEntity); // only here cast the error above
    }
}

如何忽略或修复它们?

  • VSCode v1.38.0(用户设置)
  • Node.js v10.11.0
  • Typescript v3.4.5
  • TypeORM v0.2.18

我还注意到,如果删除输入,错误就消失了: Repository&lt;MyEntity&gt;

同一行还有"Excessive stack depth comparing types 'FindConditions&lt;?&gt;' and 'FindConditions&lt;?&gt;' 错误。

【问题讨论】:

  • 除了this issue(我认为是你的)之外,还有this onethis one,所以可以肯定地认为这确实是一个错误。

标签: typescript typescript-typings typeorm typescript-3.6


【解决方案1】:

更新(2019 年 9 月 23 日):

这个问题似乎已在 Typescript 3.6.3 版中得到修复。

来源:https://github.com/typeorm/typeorm/issues/3194#issuecomment-529911310

【讨论】:

【解决方案2】:

在使用旧版本的 typescript 完成这项工作时,您还可以在 tsconfig.json 文件中添加 skipLibCheck: true 条目,如 here 所述

{
  "compilerOptions": {
    ...
    "skipLibCheck": true,
    ...
  }
}

【讨论】:

    【解决方案3】:

    这可以通过使用以前版本的 Typescript 来解决。

    首先确保工作区“npm”上的打字稿版本低于3.6。例如:package.json:

    "dependencies": {
        ...
        "typescript": "^3.0.3"
    }
    

    如果您的工作区有 3.6.x 或更高版本,请安装以前的版本,键入 npm install typescript@3.4.3

    然后,打开一个.ts 文件,一个打字稿版本选择器将出现在状态栏上。 (版本^3.6.x可能正在显示)

    然后选择“使用工作区版本”而不是“VS Code的版本”

    确保工作区版本也低于3.6.x ex 这里版本3.4.3 在我的工作区上。或者如前所述强制安装以前的版本

    既然选择了^3.4.x 版本,你应该不会在VS Code 和tsc 命令上出现这种错误。

    注意:由于工作区 Typescript 版本与 TypeORM 兼容,因此运行像 npm run build 这样的脚本不应抛出任何错误,因为它将使用 Typescript 工作区二进制文件。错误只会发生在 VS Code 或终端上的直接tsc 命令上

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-25
      • 1970-01-01
      • 2023-02-22
      • 2020-02-10
      • 2020-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多