After update to Typescript 3.5 i'm getting a lot of "Type instantiation is excessively deep and possibly infinite.ts(2589)" errors.
How can I ignore them?
Where the code happens (using 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 repo1 = connection.getRepository(MyEntity);
const repo2: Repository<MyEntity> = connection.getRepository(MyEntity); // only here cast the error above
}
}
I noted that only the repo2
initialization cast the error message.
... You should see an error:
type Test00<T1 extends any[], T2 extends any[]> =
Reverse<Cast<Reverse<T1>, any[]>, T2>
Type instantiation is excessively deep and possibly infinite. ts(2589)
It happens when TS decides that types become too complex to compute (ie). The solution is to compute the types that cause problems step by step:
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
I managed to make the error go away while still being able to compute the type properly with the usage of @ts-ignore. An example can be found in the playground, in a nutshell if you remove the // @ts-ignore
, in a full-fledged development environment, line I imagine that the code would not compile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With