I'm learning from Ben's Awad video: Fullstack React GraphQL TypeScript Tutorial. I ran into a problem with typescript.
I don't understand why compiler thinks that Post is type of {title:string}..
My code:
import { Entity, PrimaryKey, Property, OptionalProps } from '@mikro-orm/core';
import { Field, Int, ObjectType } from 'type-graphql';
@ObjectType()
@Entity()
export class Post {
[OptionalProps]?: 'title'; // id is there automatically
@Field()
@PrimaryKey()
_id!: number;
@Field(() => String)
@Property()
createdAt: Date = new Date();
@Field(() => String)
@Property({ onUpdate: () => new Date() })
updatedAt: Date = new Date();
@Field(() => String)
@Property()
title?: string;
My app.ts
const main = async () => {
const orm = await MikroORM.init(microConfig);
await orm.getMigrator().up();
const post = orm.em.create(Post, {title: 'new post'}); // here is error
await orm.em.persistAndFlush(post);
}
main();