Implement better and intuitive type definitions for Typescript #10026
SleepWalker
started this conversation in
Ideas
Replies: 1 comment 5 replies
-
I agree that |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to propose a different way of defining Model/Document types. Currently the Model class id defined as two interfaces:
Model
holds all the static props of Model classDocument
holds all other props of Model classIf we correctly define Model as class type, we will get an ability to define mongoose models as a classes, e.g.:
In the example above all the methods and properties are correctly typed and the most important thing is that this code is 100% understandable for any developer.
To use current type definitions with classes the only way I found is to cast Model (because it's value is exported without generic). But even with this hack type coverage is not the best possible:
Beta Was this translation helpful? Give feedback.
All reactions