LoginSignup
1
0

More than 5 years have passed since last update.

TypeScriptのd.tsで、既存のモジュールにプロパティを追記する方法

Posted at

nodejsでpostgresqlを使うpgモジュール、コンストラクタにプロパティが一つ足りてないので追加。
declare module~の所が重要。

import { Client } from "pg";
declare module "pg" {
    export interface ClientConfig {
        application_name?: string;
    }
}
export async function 接続済みDBを取得(config: any): Promise<Client> {
    const client = new Client({
        host: config.database.host,
        port: config.database.port,
        user: config.database.user,
        password: config.database.password,
        database: config.database.database,
        application_name: config.database.applicationName
    });
    await client.connect();
    return client;
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0