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 5.4] : error TS2321: Excessive stack depth comparing type #966

Open
ethras opened this issue Apr 16, 2024 · 2 comments
Open

Comments

@ethras
Copy link

ethras commented Apr 16, 2024

Using the latest version of edgedb and @edgedb/generate, I upgraded to latest version of Typescript (5.4.5) and started getting an error all over my code. Downgrading Typescript fixes the problem.

Code

export function getCurrentYearWorkingDocument(args: {
  year: number;
  prefix: string;
}) {
  return e
    .select(e.WorkingDocument, (order) => {

      return ({
        no: true,
        filter: e.op(order.no, 'like', `${args.prefix}${args.year}-%`)
      });
    })
    .run(client);
}

Schema

module default {
  type WorkingDocument {
        required link orderForm -> OrderForm;
        link interventionOrder -> InterventionOrder {
            on target delete allow
        }
        required property status -> WorkingDocumentStatus;
        required property documentType -> WorkingDocumentType;
        link subscriptionProposal -> MaintenanceSubscriptionProposal;
        link itemAddress -> ItemAddress;
        required property no -> str {
            constraint exclusive;
        }
        required property date -> cal::local_date;
        required property blobName -> str {
            constraint exclusive;
        }
        property pdfBlobName -> str {
            constraint exclusive;
        }
        required property key -> uuid {
            constraint exclusive;
        }
        property totalAmount -> float64;
        link invoice -> BexioInvoice {
            constraint exclusive;
            on target delete allow
        }
        link offer -> BexioOffer {
            constraint exclusive;
        }
    }
}

Error or desired behavior

error TS2321: Excessive stack depth comparing types 'getSharedParentPrimitive<P1["element"]["element"], P2["element"]["element"]>' and 'BaseType'.

Versions:

  • OS:
  • EdgeDB version (e.g. 2.0): 4.7+45e4acc
  • EdgeDB CLI version (e.g. 2.0): EdgeDB CLI 4.0.0-alpha.1+ddfbe70
  • edgedb-js version (e.g. 0.20.10;): 1.5.3
  • @edgedb/generate version (e.g. 0.0.7;): 0.5.3
  • TypeScript version: (5.4.5)
  • Node/Deno version: 20.12.0
@scotttrinh
Copy link
Collaborator

@ethras

Thanks for the report. e.op is particularly susceptible to type performance issues and 5.4 recently made things worse. I've done a bunch of work to mitigate it for some things, but e.op continues to be right on the edge. like is especially expensive due to how the overloads work since it's at the end of the list of overloads for e.op 😮‍💨

I'll keep this open while we continue to work on improving this incrementally, and we have some larger refactors coming soon that will hopefully make a much more meaningful impact on type performance.


One specific suggestion for your case:

I would consider using a mix of the queries generator for static queries like this with the query builder for more dynamic queries. The types for the queries generator are totally flat and have optimal performance compared to the more complex types in the query builder.

with
    prefix := <str>$prefix,
    year := <str>$year,
    search_term := prefix ++ year ++ "-%",
select WorkingDocument { no }
filter .no like search_term;

@ethras
Copy link
Author

ethras commented Apr 16, 2024

Thanks for your reponse and your incredible work on EdgeDB Typescript client! It's great to hear about the upcoming improvements and refactors. Using the queries generator for static queries and the query builder for dynamic ones will work fine for now :)

Thanks again!

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

No branches or pull requests

2 participants