Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
laurisvan opened this issue May 21, 2022 · 16 comments
Assignees
Labels

Comments

@laurisvan
Copy link

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 laurisvan changed the title TypeScript 4.7 Upgrade results in "" TypeScript 4.7 Upgrade results in "Type instantiation is excessively deep and possibly infinite." May 21, 2022
@laurisvan
Copy link
Author

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 laurisvan changed the title TypeScript 4.7 Upgrade results in "Type instantiation is excessively deep and possibly infinite." WIP: TypeScript 4.7 Upgrade results in "Type instantiation is excessively deep and possibly infinite." May 21, 2022
@niteshrawat1995
Copy link

@laurisvan Did you manage to solve this?

@laurisvan
Copy link
Author

My PR #2278 seems to solve the issue.

@laurisvan laurisvan changed the title WIP: TypeScript 4.7 Upgrade results in "Type instantiation is excessively deep and possibly infinite." TypeScript 4.7 Upgrade results in "Type instantiation is excessively deep and possibly infinite." May 29, 2022
@niteshrawat1995
Copy link

Any updates?

@hrmcdonald
Copy link

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

@keepcosmos
Copy link

any update or any news here?

@joshkay
Copy link

joshkay commented Sep 6, 2022

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

@keepcosmos
Copy link

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.

@falkenhawk
Copy link
Contributor

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

@ahilke
Copy link

ahilke commented Feb 13, 2023

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

@lehni
Copy link
Collaborator

lehni commented Apr 15, 2023

Could somebody provide a reproducible example similar to the one provided in #2132 (comment)

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

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

@lehni lehni self-assigned this Apr 15, 2023
@lehni lehni added the typings label Apr 15, 2023
@ahilke
Copy link

ahilke commented Apr 15, 2023

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

@lehni
Copy link
Collaborator

lehni commented Apr 15, 2023

@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

@ahilke
Copy link

ahilke commented Apr 15, 2023

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

@lehni
Copy link
Collaborator

lehni commented Apr 15, 2023

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

@johnnyshankman
Copy link

johnnyshankman commented Aug 13, 2024

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),
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants