Comments (9)
@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.
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.
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.
@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.
@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
:
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);
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.
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.
@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.
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.
@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)
- Do we need to import twice to pick up global augmentations HOT 1
- Cannot access protected field but private field inside nested class
- No error for non-existing css side effect import with `noUncheckedSideEffectImports` flag on HOT 8
- CommonJS module output broken after updating from 5.5.4 to 5.6.2 HOT 7
- Type inference when using `extend` in a generic is not consistent HOT 3
- Check when a function that uses `this` is referenced without binding it HOT 2
- Built-in URL is not compatible with `@types/node` URL
- [suggest] constructor init delegation with "strictPropertyInitialization" HOT 2
- Potential memory leak or dead recursive during auto completion HOT 2
- Incorrect type deducted for accumulator in reduce HOT 2
- moduleResolution: 'bundler' with subpath import seem to not support directory module and extensionless import HOT 4
- Source mappings are missing for serialized properties
- Missing overload method on union types HOT 6
- JSDoc `@import` of "tslib" fails under `--moduleResolution bundler`
- Interface that extends another no longer constrains types like the original HOT 1
- Proposal: Allow isolated declarations to infer results of constructor calls HOT 10
- Property 'difference' does not exist on type 'Set' HOT 3
- Type narrowing of condition leads to unexpected error for assignment HOT 3
- Increase the distinction between class and interface properties when defining a class or interface
- Add adaptation to class and interface property prompts HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.