Argument of type '{ readonly entities: readonly [typeof Post]; readonly dbName: "lireddit"; readonly type: "postgresql"; readonly debug: boolean; }' is not assignable to parameter of type 'Configuration<IDatabaseDriver> | Options<IDatabaseDriver> | undefined'. Type '{ readonly entities: readonly [typeof Post]; readonly dbName: "lireddit"; readonly type: "postgresql"; readonly debug: boolean; }' is not assignable to type 'Options<IDatabaseDriver>'. Type '{ readonly entities: readonly [typeof Post]; readonly dbName: "lireddit"; readonly type: "postgresql"; readonly debug: boolean; }' is not assignable to type 'Partial<MikroORMOptions<IDatabaseDriver>>'. Types of property 'entities' are incompatible. The type 'readonly [typeof Post]' is 'readonly' and cannot be assigned to the mutable type '(string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema<any, undefined>)[]'.ts(2345)
import { MikroORM } from '@mikro-orm/core';
import { __prod__ } from './constants';
import { Post } from './entities/Post';
import mikroConfig from './mikro-orm.config';
const main = async() => {
const orm = await MikroORM.init(mikroConfig);
const post = orm.em.create(Post, {title:'ez az első posztom hehe'})
await orm.em.persistAndFlush(post)
}
main().catch((err) => {
console.error(err)
})
import { Post } from "./entities/Post";
import { __prod__ } from "./constants";
export default {
entities:[Post],
dbName: "lireddit",
type: "postgresql",
debug : !__prod__,
} as const;
Thank you for the help i you can, its so painful
With your project directory set up, you can install TypeScript: It is important to include the --save-dev flag because it saves TypeScript as a development dependency. This means that TypeScript is absolutely required for the development of your project.
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. MikroORM allows handling transactions automatically. When you call em.flush (), all computed changes are wrapped inside a database transaction. Uses source code analysis so you do not have to repeat yourself when defining entities.
MikroORM allows handling transactions automatically. When you call em.flush (), all computed changes are wrapped inside a database transaction.
The tsc command is used here because it is the built-in TypeScript compiler. When you write code in TypeScript, running tsc will transform or compile your code into JavaScript. Using the --init flag in the above command will initialize your project by creating a tsconfig.json file in your typescript-project project directory.
The way you are defining your ORM config is wrong, you should use Options
type from the core package instead of const assertion. Define the config this way to have the best intellisense support (as well as to get rid of that TS error):
import { Options } from '@mikro-orm/core';
import { Post } from "./entities/Post";
import { __prod__ } from "./constants";
const config: Options = {
entities: [Post],
dbName: "lireddit",
type: "postgresql",
debug : !__prod__,
};
export default config;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With