Code Monkey home page Code Monkey logo

Comments (9)

ahejlsberg avatar ahejlsberg commented on September 24, 2024 1

@xixixao Thanks. With npx tsc -diagnostics I see the following:

Files:              289
Lines:            89160
Identifiers:      81591
Symbols:         214861
Types:           207767
Instantiations: 8903666
Memory used:    314029K
I/O read:         0.11s
I/O write:        0.00s
Parse time:       0.53s
Bind time:        0.12s
Check time:      14.37s
Emit time:        0.00s
Total time:      15.03s

The number that catches my eye here is the ~10M type instantiations. That is a very high number, indicative of some expensive type operations in the code base.

Unfortunately, when I compile the code base with the nightly build of the compiler (or the 5.5 beta release) I see a long list of type check errors (but not the long compile times), so I can't really debug the issue further. Looks to me like a conditional type is making a different choice with 5.5, which subsequently causes a lot of tests to error.

If you can update your repo to reproduce the issue with 5.5 beta or the nightly builds I can try to look further.

from typescript.

fatcerberus avatar fatcerberus commented on September 24, 2024

A subtype of B
X' = X<A, C>
X'' = X<B, C>
implied that X' subtype of X''
even when X<T, U> = T & U

This is not a valid assumption for arbitrary X. For example, T might be contravariant, or X might even be a conditional type in which case the resulting type relationship is entirely arbitrary.

from typescript.

ahejlsberg avatar ahejlsberg commented on September 24, 2024

It's hard to diagnose an issue without a specific example. Ideally one that fits in the playground, but if not, a repo that can be easily cloned.

from typescript.

xixixao avatar xixixao commented on September 24, 2024

@ahejlsberg appreciate you having a look! This should do the trick in a few seconds:

git clone https://github.com/xixixao/convex-ents --depth 2 -b edgebitfaster repro-convex-ents
cd repro-convex-ents
npm i
cd test
npm i
npx tsc

from typescript.

xixixao avatar xixixao commented on September 24, 2024

@ahejlsberg that looks to be caused by a potential bug in 5.5. I can't again get it to simplify, as it doesn't repro inside an individual module. But the main issue is in setup.testing.ts:

Screenshot 2024-05-20 at 17 19 44

This is caused by EntDefinition not being accepted as a subtype of TableDefinition (which comes from another npm package, and if I inline it the issue goes away):

You can replace setup.testing.ts with:

import {
  TableDefinition,
} from "convex/server";
import { EntDefinition } from "../../src";

const x: EntDefinition = null as any;

function foo(t: TableDefinition) {

}

foo(x);

And you will see the error:
Screenshot 2024-05-20 at 17 09 09

I don't know how to fix this error. TableDefinition is defined as a class, exported as a type. EntDefinition is right now defined as an interface extending TableDefinition. If change it to declare class the error stays the same.

from typescript.

ahejlsberg avatar ahejlsberg commented on September 24, 2024

Looks like you have two competing declarations of TableDefinition with the following paths (on my machine):

C:\tc\repro-convex-ents\test\node_modules\convex\src\server\schema.ts
C:\tc\repro-convex-ents\src\schema.ts

The compiler is pointing this out. We've made some fixes to module resolution in 5.5 so likely that's the cause. I would trust that 5.5 is getting it right, so you probably want to look into that.

from typescript.

xixixao avatar xixixao commented on September 24, 2024

@ahejlsberg So that's because of my funky importing from within test from the parent project, which 5.5 resolution seems to choke on (since I have the dependency installed twice). So fixed that via linking but then the issue no longer repros inside the repo.

But I can still repro it in a separate repo (set up with TS5.5 and the "broken" version of the lib):

git clone https://github.com/xixixao/saas-starter --depth 2 -b repro-ts-issue repro-convex-saas
cd repro-convex-saas
npm i -f
npx tsc -diagnostics

Gives:

Files:              1200
Lines:            197780
Identifiers:      208367
Symbols:          471886
Types:            657241
Instantiations: 17862935
Memory used:     808594K
I/O read:          0.04s
I/O write:         0.00s
Parse time:        0.69s
Bind time:         0.19s
Check time:       13.88s
Emit time:         0.02s
Total time:       14.77s

So back to the high instantiation count.

And from the trace I can see that it's the EntWriter < Ent typecheck in several places that causes this.

The only other thing I noticed is that TS caches the results in tsconfig.tsbuildinfo so it needs to be deleted to observe the full typecheck.

The library source code is on branch stillslowinstarter (vs the much faster version on the parent commit), the diff between them is:

--- a/src/functions.ts
+++ b/src/functions.ts
@@ -2375,7 +2375,15 @@ class PromiseEntWriterImpl<
 declare class EntWriterInstance<
   EntsDataModel extends GenericEntsDataModel,
   Table extends TableNamesInDataModel<EntsDataModel>,
-> extends EntInstance<EntsDataModel, Table> {
+> {
+  edge<Edge extends keyof EntsDataModel[Table]["edges"]>(
+    edge: Edge,
+  ): PromiseEdgeWriter<EntsDataModel, Table, Edge>;
+  edgeX<Edge extends keyof EntsDataModel[Table]["edges"]>(
+    edge: Edge,
+  ): PromiseEdgeWriterOrThrow<EntsDataModel, Table, Edge>;
+  doc(): DocumentByName<EntsDataModel, Table>;
+

(leaving the extends in doesn't help, TS still goes and checks that the edge and edgeX are compatible with the parent class)

from typescript.

ahejlsberg avatar ahejlsberg commented on September 24, 2024

So fixed that via linking but then the issue no longer repros inside the repo.

That may indeed be the fix. I have a hunch your issue is caused by excessive work resulting from structural comparisons of very similar (if not structurally identical) types. That can happen when you have multiple copies of the same library in a single compilation.

But I can still repro it in a separate repo (set up with TS5.5 and the "broken" version of the lib)

What is it that is "broken" here? If it is because you have multiple copies of the same types (and thus excessive work from structural comparisons), then I don't think there's much we can do.

from typescript.

xixixao avatar xixixao commented on September 24, 2024

@ahejlsberg no, I don't I have multiple copies of the same library in the second repro I shared. There's a single flat node_modules with only one copy of convex and convex-ents.

from typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.