Skip to content

[WIP] recreate the tsc crash we're seeing in mongosh #551

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lerouxb
Copy link
Collaborator

@lerouxb lerouxb commented Jun 20, 2025

This is pretty contrived while mirroring the generics setup/hierarchy in mongosh. I just copy pasted parts. Plan is to try and fix it here, then port the fix over.

Test it and reproduce the crash like this:

~/mongo/devtools-shared/packages/mql-typescript % npx ts-node tests/real.ts

/Users/leroux.bodenstein/mongo/devtools-shared/packages/mql-typescript/node_modules/typescript/lib/typescript.js:70988
  function getRelationKey(source, target, intersectionState, relation, ignoreConstraints) {
                         ^
RangeError: Maximum call stack size exceeded
    at getRelationKey (/Users/leroux.bodenstein/mongo/devtools-shared/packages/mql-typescript/node_modules/typescript/lib/typescript.js:70988:26)
    at recursiveTypeRelatedTo (/Users/leroux.bodenstein/mongo/devtools-shared/packages/mql-typescript/node_modules/typescript/lib/typescript.js:69330:18)
    at isRelatedTo (/Users/leroux.bodenstein/mongo/devtools-shared/packages/mql-typescript/node_modules/typescript/lib/typescript.js:68843:122)
    at eachTypeRelatedToType (/Users/leroux.bodenstein/mongo/devtools-shared/packages/mql-typescript/node_modules/typescript/lib/typescript.js:69204:28)
    at unionOrIntersectionRelatedTo (/Users/leroux.bodenstein/mongo/devtools-shared/packages/mql-typescript/node_modules/typescript/lib/typescript.js:69031:174)
    at structuredTypeRelatedToWorker (/Users/leroux.bodenstein/mongo/devtools-shared/packages/mql-typescript/node_modules/typescript/lib/typescript.js:69644:23)
    at structuredTypeRelatedTo (/Users/leroux.bodenstein/mongo/devtools-shared/packages/mql-typescript/node_modules/typescript/lib/typescript.js:69474:21)
    at recursiveTypeRelatedTo (/Users/leroux.bodenstein/mongo/devtools-shared/packages/mql-typescript/node_modules/typescript/lib/typescript.js:69425:19)
    at isRelatedTo (/Users/leroux.bodenstein/mongo/devtools-shared/packages/mql-typescript/node_modules/typescript/lib/typescript.js:68843:122)
    at isPropertySymbolTypeRelated (/Users/leroux.bodenstein/mongo/devtools-shared/packages/mql-typescript/node_modules/typescript/lib/typescript.js:70220:14)

return this._name;
}
async find(
query?: schema.Query<Document>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The moment you change Document to C['schema'] it crashes. I've also changed GenericCollectionSchema to BE the schema (ie. it doesn't have a 'schema' field) and then just pass C here rather than Document, but that also crashes. Note that if you change the parameter you have to change the Promise result too in lockstep because as a test I'm just returning the query.

return this._name;
}
async find(
query?: schema.Query<C['schema']>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing C['schema'] here (and in the return type) to Document does not crash.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly changing schema.Query to just be any here does not crash.

Anything more complicated than that breaks.

@coveralls
Copy link

Coverage Status

coverage: 70.429% (-2.0%) from 72.404%
when pulling 82aa8bf on test-schema
into 1770691 on main.

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

Successfully merging this pull request may close these issues.

2 participants