objection.js icon indicating copy to clipboard operation
objection.js copied to clipboard

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

Open laurisvan opened this issue 3 years ago • 9 comments

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.

laurisvan avatar May 21 '22 13:05 laurisvan

Note: This might well be specific to the fact TypeScript 4.7 being a release candidate and still having some bugs, but I wonder if somebody more versed in TypeScript complex type inference could tell if that were the case.

laurisvan avatar May 21 '22 14:05 laurisvan

@laurisvan Did you manage to solve this?

niteshrawat1995 avatar May 29 '22 06:05 niteshrawat1995

My PR #2278 seems to solve the issue.

laurisvan avatar May 29 '22 18:05 laurisvan

Any updates?

niteshrawat1995 avatar Jul 27 '22 10:07 niteshrawat1995

Been running into this same issue as well. Specifically when using returning(*) from a $query().

hrmcdonald avatar Jul 27 '22 16:07 hrmcdonald

any update or any news here?

keepcosmos avatar Aug 09 '22 01:08 keepcosmos

Running into this issue as well. Anyone have a solution?

joshkay avatar Sep 06 '22 13:09 joshkay

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.

keepcosmos avatar Sep 13 '22 02:09 keepcosmos

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

falkenhawk avatar Sep 14 '22 11:09 falkenhawk

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()

ahilke avatar Feb 13 '23 21:02 ahilke

Could somebody provide a reproducible example similar to the one provided in https://github.com/Vincit/objection.js/issues/2132#issuecomment-962988859

I have tried to reproduce this issue but have failed. This may be working now due to the change in 2cefc7735a67a6a840952c407d2a4589cc4d77ba

If somebody could test and confirm, or provide an example if the problem remains, that would be great, thanks!

lehni avatar Apr 15 '23 00:04 lehni

Hi @lehni, I am still experiencing this issue with the latest versions, i.e. [email protected] and [email protected]. I realised my example was not sufficient, apologies. I've created a reproduction repository here: https://github.com/ahilke/objection-reproduce-2277

ahilke avatar Apr 15 '23 09:04 ahilke

@ahilke I wasn't talking of the latest released version. I have since merged some TS fixes and am curious to see if they help with this. Could you install objection from master in your repo and test? e.g. following https://www.pluralsight.com/guides/install-npm-packages-from-gitgithub

lehni avatar Apr 15 '23 09:04 lehni

@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.

ahilke avatar Apr 15 '23 10:04 ahilke

Alright, thanks for the heads up! I'd say let's merge this and be done with it :)

lehni avatar Apr 15 '23 10:04 lehni