'Getting error argument of type '{ username: string; password: string; }' is not assignable to parameter of type 'RequiredEntityData<User>'

My project working fine but I'm keep getting red underline at this line of code:

{
   username: options.username,
   password: hasedPassword
}

When I hover it, it said:

Argument of type '{ username: string; password: string; }' is not assignable to parameter of type 'RequiredEntityData'. Type '{ username: string; password: string; }' is missing the following properties from type '{ createdAt: EntityDataItem; updatedAt: EntityDataItem; username: EntityDataItem; password: EntityDataItem; }': createdAt, updatedAtts(2345)

Here is the entire file:

import { User } from "../entities/User";
import { MyContext } from "../types";
import { Arg, Ctx, Field, InputType, Mutation, Resolver } from "type-graphql";
import argon2 from 'argon2';

@InputType()
class UsernamePasswordInput {
    @Field()
    username: string

    @Field()
    password: string
}

@Resolver()
export class UserResolver {
    @Mutation(() => User) 
    async register(
        @Arg('options') options: UsernamePasswordInput,
        @Ctx() {em}: MyContext
    ) {
        const hasedPassword = await argon2.hash(options.password)
        const user = em.create(User, {
            username: options.username,
            password: hasedPassword
        })
        await em.persistAndFlush(user)
        return user
    }
}

package.json:

{
  "name": "practicegraphQL",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "watch": "tsc -w",
    "dev": "nodemon dist/index.js",
    "start": "ts-node src/index.ts",
    "create:migration": "mikro-orm migration:create"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.35",
    "nodemon": "^2.0.16",
    "ts-node": "^10.8.0",
    "typescript": "^4.6.4"
  },
  "dependencies": {
    "@mikro-orm/cli": "^5.1.4",
    "@mikro-orm/core": "^5.1.4",
    "@mikro-orm/migrations": "^5.1.4",
    "@mikro-orm/postgresql": "^5.1.4",
    "apollo-server-express": "^2.25.3",
    "argon2": "^0.28.5",
    "express": "^4.18.1",
    "graphql": "15.7.2",
    "pg": "^8.7.3",
    "reflect-metadata": "^0.1.13",
    "type-graphql": "^1.1.1"
  },
  "mikro-orm": {
    "useTsNode": true,
    "configPaths": [
      "./src/mikro-orm.config.ts",
      "./dist/mikro-orm.config.js"
    ]
  }
}

How can I fix this error ?

Updated, added User entity:

@ObjectType()
@Entity()
export class User {

  @Field()
  @PrimaryKey()
  _id!: number;

  @Field(() => String)
  @Property()
  createdAt: Date = new Date();

  @Field(() => String)
  @Property({ onUpdate: () => new Date() })
  updatedAt: Date = new Date();

  @Field(() => String)
  @Property({unique: true})
  username!: string;
    
  @Property()
  password!: string;

}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source