对象文字只能指定已知属性,并且CLI' Type typeormoduleoptions中不存在
我正在尝试将Nest JS项目中的迁移与CLI一起设置,但是无论我做什么,TypeOmm始终在CLI上发誓。 已经有很多天了,我很难过。
错误ts2322:type'{type'{type'{type:“ postgres”;主机:字符串;端口:号码;用户名:字符串;数据库:字符串;密码:字符串;实体:字符串[];迁移:字符串[]; CLI:{MigrationsDir:String; };额外:{charset:string; };同步:false;记录:是的; }'不能分配给'TypeModuleOptions'。 对象文字只能指定已知属性,而“ cli”在type'{retryAttEmpts中不存在?:number; retrydelay?:编号; toretry?:( err:no)=>布尔;自动加载?:布尔值; keepconnectional? verboseretrylog?:布尔值; }&部分的'。
I'm trying to set up migrations in my Nest JS project along with the cli, but no matter what I do, typeorm always swears on the cli.
It's been many days and I'm stumped.
error TS2322: Type '{ type: "postgres"; host: string; port: number; username: string; database: string; password: string; entities: string[]; migrations: string[]; cli: { migrationsDir: string; }; extra: { charset: string; }; synchronize: false; logging: true; }' is not assignable to type 'TypeOrmModuleOptions'.
Object literal may only specify known properties, and 'cli' does not exist in type '{ retryAttempts?: number; retryDelay?: number; toRetry?: (err: any) => boolean; autoLoadEntities?: boolean; keepConnectionAlive?: boolean; verboseRetryLog?: boolean; } & Partial'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用TypeORM 0.3.x,那么TypeOmm-CLI现在需要迁移路径作为命令选项。您可以删除该部分打字稿抱怨并检查此线程。 typeorm/typeorm/nest-用'useFactory` running迁移
If you use typeorm 0.3.x, typeorm-cli needs migration path as a command option now. You can delete that part typescript complains and check this thread. TypeORM/nest - running migrations with `useFactory`
您ORM配置应该是DataSource的实例
ormconfig.ts文件
像这样:
导出默认新dataSource({
类型:“ Postgres”,
主机:process.env.postgres_host
端口: +process.env.postgres_port,
用户名:process.env.postgres_user,
密码:process.env.postgres_db_password,
数据库:process.env.postgres_database,
实体:[__dirname +'//* entity {.ts,.js}'],
同步:false,
迁移:[__dirname +'/migrations//* {.ts,.js}'],
});
添加到package.json下一个命令:
You ORM config should be instance of DataSource
ormconfig.ts file
like this:
export default new DataSource({
type: 'postgres',
host: process.env.POSTGRES_HOST
port: +process.env.POSTGRES_PORT,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_DB_PASSWORD,
database: process.env.POSTGRES_DATABASE,
entities: [__dirname + '//*.entity{.ts,.js}'],
synchronize: false,
migrations: [__dirname + '/migrations//*{.ts,.js}'],
});
add to package.json next commands: