edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

[Typescript 5.4] : error TS2321: Excessive stack depth comparing type

Open ethras opened this issue 10 months ago • 2 comments

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

ethras avatar Apr 16 '24 06:04 ethras

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

scotttrinh avatar Apr 16 '24 12:04 scotttrinh

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!

ethras avatar Apr 16 '24 13:04 ethras

any updates on this?

lostfutures avatar Jul 23 '24 17:07 lostfutures

@lostfutures

Indeed! https://github.com/edgedb/edgedb-js/pull/1039 should fix this and is available by updating your @edgedb/generate and edgedb packages to the canary tag which includes those fixes. Will work on getting a latest release out soon.

scotttrinh avatar Jul 23 '24 18:07 scotttrinh

Closed in #1039

scotttrinh avatar Jul 23 '24 18:07 scotttrinh