I'm trying to code along to this React GraphQL TypeScript tutorial
The project uses MikroOrm to communicate with a PostgreSQL database.
Goal: To create an instance of post and insert it into the database.
Currently I'm at minute 19.53 and I'm stuck with the following error which does not appear in the video, I'm not sure why.
Post.ts file:
@Entity() //correspond to database table.
export class Post {
@PrimaryKey()
id!: number;
@Property({ type: 'date'}) //denote database column, without it its just a class attribute
createdAt = new Date();
@Property({ type: 'date', onUpdate: () => new Date() })
updatedAt = new Date();
@Property({type: 'text'})
title!: string;
}
Index.ts file:
const main = async () => {
const orm = await MikroORM.init(microConfig);
const post = orm.em.create(Post, {title: "my first post" }); //create instance of post
await orm.em.persistAndFlush(post); //insert into database
}
The line in Index.ts is throwing me an error:
const post = orm.em.create(Post, {title: "my first post" });
Argument of type '{ title: string; }' is not assignable to parameter of type 'RequiredEntityData<Post>'.
Type '{ title: string; }' is missing the following properties from type '{ createdAt: EntityDataItem<Date>; updatedAt: EntityDataItem<Date>; title: EntityDataItem<string>;