更新为Typescript 3.5后,我收到很多“类型实例化过深,甚至可能是infinite.ts(2589)”错误。
我该如何忽略它们?
代码发生的位置(使用TypeORM)
<canvas id="canvas" width="300" height="300">
我注意到只有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 repo1 = connection.getRepository(MyEntity);
const repo2: Repository<MyEntity> = connection.getRepository(MyEntity); // only here cast the error above
}
}
初始化会投射错误消息。
答案 0 :(得分:3)
...您应该看到一个错误:
type Test00<T1 extends any[], T2 extends any[]> =
Reverse<Cast<Reverse<T1>, any[]>, T2>
类型实例化的深度过大,甚至可能是无限的。 ts(2589)
当TS决定类型变得太复杂而无法计算时(即),就会发生这种情况。 解决方案是逐步计算出导致问题的类型:
type Test01<T1 extends any[], T2 extends any[]> =
Reverse<Reverse<T1> extends infer R ? Cast<R, any[]> : never, T2>
https://github.com/microsoft/TypeScript/issues/30188#issuecomment-478938437
答案 1 :(得分:0)
我设法使错误消失了,同时仍然能够使用 @ ts-ignore 正确计算类型。简而言之,如果您删除了// @ts-ignore
,可以在playground中找到一个示例,在成熟的开发环境中,我想代码无法编译。