【发布时间】:2020-07-21 13:55:42
【问题描述】:
您好,我的 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;
我无法想象如何解决这个问题 如果有人可以帮助我,我将不胜感激
【问题讨论】:
-
如果你在
createConnection({...})内联设置配置对象而不导入它是否有效? -
请在那里查看我的回答。我为 postgres 编写了示例工作配置,可能会对您有所帮助:stackoverflow.com/questions/63678216/…
标签: typescript typeorm