objection.js: TypeScript 4.7 Upgrade results in "Type instantiation is excessively deep and possibly infinite."

This is a followup to issue #1668, which seems to resurface with the latest TypeScript (4.7 RC1) upgrade.

Queries of type

await this.$query()
  .patch({
    ...update
  })
  .returning('*')

Result in TS error TS2589: Type instantiation is excessively deep and possibly infinite..

It appears it is related to this.$query() type of queries, and particularly to .returning('*'). The model class used in the app is of type export class WorkPlan extends RescommsModel (where RescommsModel is of type export class RescommsModel extends Model), but it appears that inheriting directly from Objection Model does not make any difference.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 16 (1 by maintainers)

Commits related to this issue

Most upvoted comments

For the record, I was getting issues with this when downgrading a version of knex to match my objection version after realizing i had version conflicts (a PSA to always use NPM or non legacy yarn to avoid that)

The source of the error was not because of a typescript nor an objection/knex versions issue per say.

The error message is obtuse but it did surround a genuine type error in my calls to things like insert() and insertAndFetch(). I was passing a datetime string instead of a JS Date for Objection.Expression<Date>

Before

const snapshot = await AudienceSnapshot.query().insert({
      name,
      // ....
      // @note: causes error of "Type instantiation is excessively deep and possibly infinite." 
      timestamp: someDateTimeString,
 });

After

const snapshot = await AudienceSnapshot.query().insert({
     name,
     // ...
     // @note: the fix, objection expects a JS Date not a datetime string here
     timestamp: new Date(timestamp),
});

Same thing happens with typescript 4.7.x. But the issue is no longer reproduced in typesciprt 4.8.3. seems to have been resolved.

unfortunately, no change in my case in typescript 4.8.3, still getting same amount of TS2589: Type instantiation is excessively deep and possibly infinite. errors, as in 4.7.3

Any updates?

@lehni Oh, sorry, didn’t realise those changes were not released yet. I’ve installed master (commit 9b92eb11d1f9278d4c58f0cfb820757f9e65eeea), but still experience the same error. Updated the repo accordingly.

But the issue is no longer reproduced in typesciprt 4.8.3. seems to have been resolved.

I’m also encountering this issue with latest typescript 4.9.5 and objection 2.2.18. Occurs in a query using both first() as well as returning(*).

Specifically, my query looks like this where this.Model is a generic ModelClass<MyModel>:

this.Model.query()
      .patch({ updatedBy })
      .returning('*')
      .where('id', id)
      .first()

Same thing happens with typescript 4.7.x. But the issue is no longer reproduced in typesciprt 4.8.3. seems to have been resolved.