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
Can't get typegoose import and types in $push accepted by typescript at the same time #339
Comments
currently es6 modules(esm) are not supported by typegoose (look #214)
tsconfig option cannot reproduce, code used: // NodeJS: 14.7.0
// MongoDB: 4.2-bionic (Docker)
import { getModelForClass, prop } from "@typegoose/typegoose"; // @typegoose/typegoose@7.3.1
import * as mongoose from "mongoose"; // mongoose@5.9.26 @types/mongoose@5.7.34
class MyClass {
@prop({ items: String, default: [], })
public thisIsAnArray?: string[];
}
const MyClassModel = getModelForClass(MyClass, {
schemaOptions: { collection: "myClass" },
});
(async () => {
await mongoose.connect(`mongodb://localhost:27017/`, { useNewUrlParser: true, dbName: "verify339", useCreateIndex: true, useUnifiedTopology: true });
const doc = new MyClassModel({});
const myClass = await MyClassModel.findOneAndUpdate({
_id: doc,
}, {
$push: {
thisIsAnArray: "hello there" // has the correct typing and no error
}
}).lean();
await mongoose.disconnect();
})(); do you have PS: i edited your issue for better readability |
Hi, thanks for the answer and trying to reproduce. Yes I did install @types/mongoose (updated it too just in case). Story is I temporary used "require" everywhere because I couldn't afford digging more right now into it. After my cleaning/refactoring, all of a sudden it started working like a charm ... I don't know exactly why but I also did two things in the meanwhile : 1/ I removed package-lock and re-built (for some other issues) 2/ Set this tsconfig :
I have it all on a separate branch I'll check out of curiosity, and it's time for me to dig deeper into the different modules ... Thanks a lot anyway for your help and library. I'm using it since it was hosted on your account, I really enjoy the simplicity it adds. Our last year MVP and pivots did benefit a lot from it 👍 Edit: as you couldn't reproduce it (and me neither on a new project) and it was solved by deleting package.lock I closed it, I hope it's ok |
@adzaria Did you figure out what is the cause of this typescript error? |
Any updates on this? Having the same issue. |
@loicnestler no updates, could you list your used versions? typegoose, mongoose, typescript, @types/mongoose |
@hasezoey actually it was my bad. :oops: Thank you for quick response tho! Still, in case anyone else has this issue: |
Hi all, first of all thanks for typegoose, I love it and I've been using it in production for the last 6 months (probably foolish but I really enjoy working with it).
My issue is probably just about me not knowing modules well enough (I just upgraded from typegoose from 6ish to 7.3.1).
Here is my model:
Here is my code:
My issue is that Webstorm throws an error and tsc won't compile.
for thisIsAnArray (in findOneAndUpdate) it tells me
TS2769: No overload matches this call. The last overload gave the following error. Type string is not assignable to type 'undefined'.
I played with tsconfig options a bit (changed commonjs modules to ES15), now the error is gone, but when I import
import {prop, getModelForClass} from '@typegoose/typegoose;'
it tells me
TS2307: Cannot find module '@typegoose/typegoose' or its corresponding type declarations.
I tried to play with :
There is always one or the other that has a problem, I can't get to have both working ...
(I tried importing typegoose from @typegoose/typegoose, then destructuring functions, but the same issue always appears)
Edit:
I am using this trick for now ... (There are others but it will be the less painfull to refactor)
The text was updated successfully, but these errors were encountered: