Type mismatch when setting up connection #569
-
Hello everybody, I'm trying to centralize my application configuration, so I've made a export default {
postgres: {
host: process.env.PGHOST ?? 'localhost',
port: process.env.PGPORT ?? 5432,
database: process.env.PGDATABASE ?? 'neps',
username: process.env.PGUSER ?? 'neps',
password: 'neps',
}
}; The idea is to be able to use the standard Postgresql environment configuration variables. But even when I'm using the nullish coalescing operator, Typescript complains with the following error:
The problem goes away if I remove the environment variables, so I understand Typescript is complaining about the possibility of them being I understand that this may be a "general Typescript" question, but I preferred to ask here first since it involves specific |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Actually, typescript complains that:
The last line is the most specific. In order to satisfy the {
port: parseInt(process.env.PGPORT, 10) || 5432
} |
Beta Was this translation helpful? Give feedback.
Actually, typescript complains that:
The last line is the most specific.
In order to satisfy the
Options
type, you would have to do something like this: