My attempt to establish a connection to an AWS MySQL database looks like this:
const config = {
host: process.env.RDS_HOSTNAME,
user: process.env.RDS_USERNAME,
password: process.env.RDS_PASSWORD,
port: 3306,
database: process.env.RDS_DB_NAME,
}
const db = mysql.createConnection(config) // the 'config' here is highlighted
However, I encounter the following error message:
Argument of type '{ host: string | undefined; user: string | undefined; password: string | undefined; port: number; database: string | undefined; }' is not assignable to parameter of type 'string | ConnectionConfig'.
Type '{ host: string | undefined; user: string | undefined; password: string | undefined; port: number; database: string | undefined; }' is not assignable to type 'ConnectionConfig'.
Types of property 'host' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.ts(2345)
Previously, I encountered an issue with the port being sourced from .env
. After switching to setting the port directly, this problem emerged.
The cause of the issue and its resolution elude me at this point.