TypeORM 在存储库键入时抛出 "Type instantiation is excessively deep and possibly infinite.ts(2589)" 错误
TypeORM throws "Type instantiation is excessively deep and possibly infinite.ts(2589)" error on Repository typing
更新到 VSCode August 2019 (version 1.38) and Typescript 3.6 i'm getting a lot of Type instantiation is excessively deep and possibly infinite.ts(2589)
on TypeORM 存储库初始化后。
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
- 打字稿 v3.4.5
- TypeORM v0.2.18
我还注意到,如果删除输入,错误就会消失 : Repository<MyEntity>
同一行还有 "Excessive stack depth comparing types 'FindConditions<?>' and 'FindConditions<?>'
错误。
这可以通过使用旧版本的 Typescript 来解决。
首先确保您工作区 "npm" 上的打字稿版本低于 3.6
。例如:package.json
:
"dependencies": {
...
"typescript": "^3.0.3"
}
如果您的工作区有 3.6.x
或更高版本,请输入 npm install typescript@3.4.3
安装以前的版本
然后,打开 .ts
文件,打字稿版本选择器将出现在状态栏上。 (可能显示版本 ^3.6.x
)
然后选择 "Use Workspace Version" 而不是 "VS Code's Version"
确保工作区版本也低于 3.6.x
ex 这里版本 3.4.3
在我的工作区。或者如前所述强制安装以前的版本
既然选择了版本 ^3.4.x
,那么在 VS Code 和 tsc
命令上都不应该出现此类错误。
注意:由于工作区 Typescript 版本与 TypeORM 兼容,运行 脚本如 npm run build
不应抛出任何错误,因为它将使用 Typescript 工作区二进制文件。错误只会发生在 VS Code 或终端
上的直接 tsc
命令上
虽然使用旧版本的打字稿可以完成这项工作,但您还可以按照 here
所述在 tsconfig.json
文件中添加 skipLibCheck: true
条目
{
"compilerOptions": {
...
"skipLibCheck": true,
...
}
}
更新(2019 年 9 月 23 日):
此问题似乎已在 Typescript 版本 3.6.3 中修复。
来源:https://github.com/typeorm/typeorm/issues/3194#issuecomment-529911310
更新到 VSCode August 2019 (version 1.38) and Typescript 3.6 i'm getting a lot of Type instantiation is excessively deep and possibly infinite.ts(2589)
on TypeORM 存储库初始化后。
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
- 打字稿 v3.4.5
- TypeORM v0.2.18
我还注意到,如果删除输入,错误就会消失 : Repository<MyEntity>
同一行还有 "Excessive stack depth comparing types 'FindConditions<?>' and 'FindConditions<?>'
错误。
这可以通过使用旧版本的 Typescript 来解决。
首先确保您工作区 "npm" 上的打字稿版本低于 3.6
。例如:package.json
:
"dependencies": {
...
"typescript": "^3.0.3"
}
如果您的工作区有 3.6.x
或更高版本,请输入 npm install typescript@3.4.3
然后,打开 .ts
文件,打字稿版本选择器将出现在状态栏上。 (可能显示版本 ^3.6.x
)
然后选择 "Use Workspace Version" 而不是 "VS Code's Version"
确保工作区版本也低于 3.6.x
ex 这里版本 3.4.3
在我的工作区。或者如前所述强制安装以前的版本
既然选择了版本 ^3.4.x
,那么在 VS Code 和 tsc
命令上都不应该出现此类错误。
注意:由于工作区 Typescript 版本与 TypeORM 兼容,运行 脚本如 npm run build
不应抛出任何错误,因为它将使用 Typescript 工作区二进制文件。错误只会发生在 VS Code 或终端
tsc
命令上
虽然使用旧版本的打字稿可以完成这项工作,但您还可以按照 here
所述在tsconfig.json
文件中添加 skipLibCheck: true
条目
{
"compilerOptions": {
...
"skipLibCheck": true,
...
}
}
更新(2019 年 9 月 23 日):
此问题似乎已在 Typescript 版本 3.6.3 中修复。
来源:https://github.com/typeorm/typeorm/issues/3194#issuecomment-529911310