I trying to save data to a mongoose model on NextJS page. I get a typescript error on this line:
await User.create(data)
This expression is not callable. Each member of the union type '{ <Z = Document | _AllowStringsForIds<Pick<Pick<_LeanDocument<Document>, "_id" | "__v" | "id">, "_id" | "__v" | "id">>>(doc: Z): Promise<...>; <Z = Document<...> | _AllowStringsForIds<...>>(docs: Z[], options?: SaveOptions): Promise<...>; <Z = Document<...> | _AllowStringsForIds<...>>(...docs: Z[]): Promis...' has signatures, but none of those signatures are compatible with each other.
The code works - I can see the data added into the database, but
- Deploy on heroku fails with the same error
- I want to clear this error on my VSCode [Problems] tab as well (anoying)
Here is what I export from my User model:
export default (mongoose.models.User || mongoose.model('User', UserSchema));