Add TypeScript definition files #115
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello @nodkz,
After graphql-compose/graphql-compose#82, I'm happy to propose definition files for graphql-compose-mongoose aswell.
Again, it's a "rapid" port from the flow version.
I've copied all the configuration from graphql-compose so you've got the same commands, structure and configuration files.
I've typed all of the API except the discriminators part. It's a bit complicated and I don't want to create too much files. Also, it's probably less used than the classic API.
For the part that has been typed, I've typed all exported symbols at module's level. That means not only what's just accessible on lib/index.d.ts, but all internal contents of the library. This is still useful when you have a semi-public API on submodules, or to maintain individual files by just copying the structure of the .js counterpart without wondering each time if it's exported by lib/index.d.ts.
I think it's the same in graphql-compose, but I don't really remember. Should we keep it like that?
I've also left a few
@ts-todo-marked comments where porting the Flow version was not possible/difficult:It's been tested in my latest project.
I think it may also interest @mernxl in #107 (comment) even id I didn't typed his feature 😄
I've made
composeWithMongooseDiscriminatorsuseable though, but the rest of this API is not available.To answer his question about generated definitions, no, .d.ts generators are not really useable, runtime-based ones provide wrong or low-quality files, and Flow to TS converters are still experimental and will probably stay so.
I want to thank you again for all the work you've done on these libraries. My team uses compose libraries on all new projects and we're really happy with them. That's hundreds of hours or LoCs saved.
We're using the mongoose plugin from the beginning but I've never taken the time to type it like the main one, and we were still using an auto-generated stub of very low quality. I would be happy to benefit from real typings!