gpt4 book ai didi

Typescript 和 typeorm config .ts 没有重载匹配此调用

转载 作者:行者123 更新时间:2023-12-04 09:25:47 26 4
gpt4 key购买 nike

你好,我的 app.ts 有问题当从我的 ormconfig.ts 加载我的设置时,typeorm 函数创建连接我的应用程序出现此错误:

No overload matches this call.
Overload 1 of 3, '(name: string): Promise<Connection>', gave the following error.
Argument of type 'typeof import("d:/EmasaTi_StockControl/src/shared/infra/http/ormconfig")' is not assignable to parameter of type 'string'.
Overload 2 of 3, '(options: ConnectionOptions): Promise<Connection>', gave the following error.
Argument of type 'typeof import("d:/EmasaTi_StockControl/src/shared/infra/http/ormconfig")' is not assignable to parameter of type 'ConnectionOptions'.
Type 'typeof import("d:/EmasaTi_StockControl/src/shared/infra/http/ormconfig")' is missing the following properties from type 'ExpoConnectionOptions': type, database, driverts(2769)
Peek Problem (Alt+F8)
No quick fixes available

代码:

import 'dotenv/config';
import { createConnection } from 'typeorm';
import App from './app';
import validateEnv from '@utils/validateEnv';
import * as config from './ormconfig';
validateEnv();

(async () => {
try {
const connection = await createConnection(config);
await connection.runMigrations();
} catch (error) {
console.log('Error while connecting to the database', error);
return error;
}
const app = new App(
);
app.listen();
})();

我的配置文件:

import { ConnectionOptions } from 'typeorm';

const rootDir = process.env.NODE_ENV === 'development' ? 'src' : 'build/src';
export const config: ConnectionOptions = {
type: 'postgres',
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT),
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
entities: [rootDir + '/entities/**/*.{js,ts}'],
migrations: [rootDir + '/migrations/*.{js,ts}'],
subscribers: [rootDir + '/subscribers/**/*.{js,ts}'],
cli: {
entitiesDir: `${rootDir}/entities`,
migrationsDir: `${rootDir}/migration`,
subscribersDir: `${rootDir}/subscriber`,
},
synchronize: false,
logging: true
};

module.exports = config;

我无法想象如何解决这个问题如果有人能帮助我,我将不胜感激

最佳答案

我不确定什么是完美的解决方案,但我找到了解决它的方法。

  1. 视情况从您的 tsconfig.json 或其他配置文件中删除 "type": "mysql"
  2. 照常导入您的配置。示例:从“./ormconfig.json”导入配置
  3. 像这样使用 config 变量:createConnection({type: "postgres", ...config})

我认为由于某些原因,type 键没有被正确解析。

干杯。

关于Typescript 和 typeorm config .ts 没有重载匹配此调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63016126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com