How to specify Typescript Mongoose model type in await

Niyaz

I have to save a user in user model

            const userDoc: Document =  new User(user);
            const userData: UserModel  = await userDoc.save();

the below warning is coming when i specify type on userdata

Type 'Document' is not assignable to type 'UserModel'. Type 'Document' is not assignable to type '{ email: string; password: String; phone: Number; verificationToken: String; emailVerified: Boole...'. Property 'email' is missing in type 'Document'

Matt McCutchen

If you look at the declaration of save, it returns a promise for the same type as the object on which it is called:

save(options?: SaveOptions, fn?: (err: any, product: this) => void): Promise<this>;

Thus, declaring userDoc as type User or UserModel or just removing the type annotation on userDoc should help.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to dynamically specify type in TypeScript generics?

From Dev

How to specify type of index of enum in typescript

From Dev

How to export a Mongoose model from a CommonJS module in TypeScript NodeJS app

From Dev

How to export a Mongoose model from a CommonJS module in TypeScript NodeJS app

From Dev

How can I specify a return type for a $http call with Typescript?

From Dev

How to specify that a function returns a certain type when new'ed in TypeScript?

From Dev

Mongoose schema/model using typescript

From Dev

Mongoose + Typescript -> Exporting model interface

From Dev

Representing Mongoose model as a Typescript class

From Dev

How to specify `this` in Mongoose Schema methods

From Dev

How to specify `this` in Mongoose Schema methods

From Dev

Typescript: Specify type in object declaration

From Dev

How to specify type for a variable?

From Dev

How to specify covariates in a regression model

From Java

Specify return type in TypeScript arrow function

From Dev

TypeScript Specify Type For Individual Function Use

From Dev

how to use anync await in mongoose virtuals?

From Dev

Referencing an object with an unknown model-type with Mongoose

From Dev

Mongoose query model where field type is an array

From Dev

How to stub methods in a Mongoose model?

From Dev

Mongoose How to update nested model?

From Dev

How to specify relationship type in CSV?

From Dev

How to not specify the data type of arguments?

From Dev

How to specify data type for hashtable?

From Dev

How to specify name of configuration type?

From Dev

How to specify relationship type in CSV?

From Dev

How to specify type for lambda expression?

From Java

How to specify "nullable" return type with type hints

From Dev

How to specify "own type" as return type in Kotlin

Related Related

  1. 1

    How to dynamically specify type in TypeScript generics?

  2. 2

    How to specify type of index of enum in typescript

  3. 3

    How to export a Mongoose model from a CommonJS module in TypeScript NodeJS app

  4. 4

    How to export a Mongoose model from a CommonJS module in TypeScript NodeJS app

  5. 5

    How can I specify a return type for a $http call with Typescript?

  6. 6

    How to specify that a function returns a certain type when new'ed in TypeScript?

  7. 7

    Mongoose schema/model using typescript

  8. 8

    Mongoose + Typescript -> Exporting model interface

  9. 9

    Representing Mongoose model as a Typescript class

  10. 10

    How to specify `this` in Mongoose Schema methods

  11. 11

    How to specify `this` in Mongoose Schema methods

  12. 12

    Typescript: Specify type in object declaration

  13. 13

    How to specify type for a variable?

  14. 14

    How to specify covariates in a regression model

  15. 15

    Specify return type in TypeScript arrow function

  16. 16

    TypeScript Specify Type For Individual Function Use

  17. 17

    how to use anync await in mongoose virtuals?

  18. 18

    Referencing an object with an unknown model-type with Mongoose

  19. 19

    Mongoose query model where field type is an array

  20. 20

    How to stub methods in a Mongoose model?

  21. 21

    Mongoose How to update nested model?

  22. 22

    How to specify relationship type in CSV?

  23. 23

    How to not specify the data type of arguments?

  24. 24

    How to specify data type for hashtable?

  25. 25

    How to specify name of configuration type?

  26. 26

    How to specify relationship type in CSV?

  27. 27

    How to specify type for lambda expression?

  28. 28

    How to specify "nullable" return type with type hints

  29. 29

    How to specify "own type" as return type in Kotlin

HotTag

Archive