i'm studying TS and building a microconfig file like:
import { __prod__ } from './constants'
import { Options, MikroORM } from '@mikro-orm/core'
import path from 'path'
const config: Options = {
migrations: {
path: path.join(__dirname, './migrations'),
pattern: /^[\w-] \d \.[tj]s$/,
},
entities: [Post],
dbName: 'lireddit',
user: 'postgres',
password: 'StrongPassword',
type: 'postgresql',
debug: !__prod__,
} as Parameters<typeof MikroORM.init>[0];
export default config;
when i try to compile the console gives me this:
src/mikro-orm.config.ts:6:7 - error TS2322: Type 'Options<IDatabaseDriver<Connection>> | Configuration<IDatabaseDriver<Connection>> | undefined' is not assignable to type 'Options<IDatabaseDriver<Connection>>'.
Trying to create mikroConfig file to MikroORM with typescript and i got this error message, when i try to compile, that's a type error, but i cant figure out whats the problem.
CodePudding user response:
You don't need to give config
the type Options
.
Remove the type annotation here:
const config: Options = {
so it becomes:
const config = {
It's complaining because you are casting it to Parameters<typeof MikroORM.init>[0]
. This type includes undefined
and undefined
is not assignable to type Options
.
Also I'm pretty sure in Ben Awad's tutorial he removes this type annotation and demonstrates the usage of as
to fix another error, so make sure to rewatch that part closely. If you got questions specifically about his reddit clone, you can join his Discord server as well.