-
Notifications
You must be signed in to change notification settings - Fork 73
[Do Not Merge] PoC for shell-api autocomplete type definitions #1802
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: main
Are you sure you want to change the base?
Conversation
```sh cd packages/shell-api && \ npm run compile && \ npx api-extractor run ; \ npx ts-node bin/api-postprocess.ts ; \ cat lib/api-processed.d.ts ```
getCollection(name: string): Collection { | ||
getCollection<KD extends StringKey<M>, KC extends StringKey<M[KD]>>( | ||
name: `${KD}.${KC}` | ||
): Collection<M, M[KD], M[KD][KC]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kmruiz Wanted to highlight this, doubt many people will actually use .getCollection()
on a Mongo object ... but this is interesting, TS is not able to autocomplete the name
argument for me (which, like, fair enough), but if I pass a valid <db>.<collection>
namespace, it will return a collection with the correct schema, kind of interesting that it only partially works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That feels like a bug right? If I recall, it should be able to autocomplete on string templates. But yeah everyone will use db.collection
as you said, I don't see any reason now for not suggesting the usage of collections using property access instead of getCollection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's struggling a bit with the fact that the second part (collection name) after the .
depends on the first part (database name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, this seems like a hard problem to solve for a compiler to be fair.
(api-extractor will dump a ton of errors)