I'm trying to get TypeOrm working, and instead of creating a connection in my index.ts file like the documentation suggests, I'd like to abstract the connection into its own class to be able to import it wherever I need it.
I'm using an ormconfig file for TypeOrm options. For some reason Typescript tells me that my connection getter in the class is missing a '(' and I cannot figure out why that is.
Any idea?
import { createConnection, Connection } from 'typeorm'
export class DatabaseConnection {
private _connection: Connection;
public get async connection(): Connection { // 'connection()' is underlined with the error message "expected '('"
if (!this._connection) {
this._connection = await createConnection()
}
return this._connection
}
}