-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Provide a definitely typed file (.d.ts) for TypeScript #3949
Comments
You're more than welcome to contribute one. I have zero experience with TypeScript. |
I'd consider this pretty importing seeing as TypeScript is on the rise. I have no experience with all the quirks of writing definition files, but they should be done by someone who knows the mongoose API really well. |
@juergenzimmermann @DamonGant I've updated the Typescript definitions, please try them here: |
@simonxca OK, I installed typings and mongoose.d.ts from Definitely Typed (via typings). Now I'm getting tons of Errors like this one: |
@juergenzimmermann It's installed via typings for now using From what I hear, they are planning to move everything to @types/mongoose in the future, but they haven't quite worked out the details. @types/mongoose is in another format, and for now it looks like someone from DefinitelyTyped manually converts the definitions so they're probably outdated. |
@juergenzimmermann Don't think
If you're using the default mpromise, you should: If you're using native ES6 promises, add a line in your main .d.ts file: If you're using another library, example q, you should: If you get more errors please copy some of them on here and I'll take a look. |
@simonxca got it, thank you. Now only 2 errors are remaining.
This is my source code:
How do I have to import the class The other compilation error is
|
@juergenzimmermann For the first error, there was a You should use
Let me know if that makes sense. Actually these types are not final yet. I could change it to be like this:
Do you think that would make more sense? For the second error, that is an error with the definitions. Good catch! I'll add a fix for it. Try commenting out the |
@simonxca Thank you very much! Both issues (i.e. I'd prefer the current variant, i.e. |
@juergenzimmermann Great! Thanks for your feedback. |
@simonxca a new issue came up, since Mongoose deprecated the mpromise library. Therefore; I'm doing the following according to #4291:
But now I'm getting this error message when compiling with TypeScript:
|
@juergenzimmermann Hmm, I've never seen that before. I also can't reproduce it with the latest version of Typescript.
|
@juergenzimmermann Or try |
Thank you @simonxca . |
or you can use |
@simonxca I'm still seeing a similar error concerning the 970 class Array<T> extends global.Array {
~~~~~
typings/globals/mongoose/index.d.ts(970,13): error TS2415: Class 'Array<T>' incorrectly extends base class 'any[]'.
Types of property 'sort' are incompatible.
Type '(compareFn?: ((a: T, b: T) => number) | undefined) => any[]' is not assignable to type '(compareFn?: ((a: any, b: any) => number) | undefined) => this'.
Type 'any[]' is not assignable to type 'this'.
3:37:41 PM - Compilation complete. Watching for file changes. I'm using
|
@serhiisol @derenio Looks like Typescript's |
@simonxca Running into the same build error with |
@douglasg14b The DT definitions have it commented out so it should work out of the box now. The inherited |
I am getting an error on the
|
@fpereira1 yea, something's weird about the |
@simonxca I am basically trying something like this:
without the line above added to my version of the mongoose typings in the
|
@fpereira1 hmm okay I added your line here. Could you give the fix a try? https://raw.githubusercontent.com/simonxca/DefinitelyTyped/patch-mongoose/mongoose/index.d.ts |
i can't find the definition for MongooseDocumentArray! |
@phra https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/mongoose/index.d.ts#L1241 |
@simonxca found, thanks! |
Gonna close this. DefinitelyTyped has support for this and TS support is outside the scope of core mongoose. |
There is only a .d.ts file for mongoose 3.x at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/mongoose/mongoose.d.ts.
Therefore, you get tons of syntax errors when using this outdated file together with mongoose 4.4.6.
The text was updated successfully, but these errors were encountered: