Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

658
Visualizações
TypeScript: undefined is not assignable to type 'boolean | ConnectionOptions | undefined

I am working with the below code-block, I built it a couple of months ago in JavaScript, but las week I decided to start learning TypeScript. I cant seem to find how to properly defined the data types. Does any one have any hints or resources that can aid me to solve this issue?


this is the exact error message:

src/utils/pool.ts:5:5 - error TS2322: Type '"" | { rejectUnauthorized: false; } | undefined' is not assignable to type 'boolean | ConnectionOptions | undefined'. Type '""' is not assignable to type 'boolean | ConnectionOptions | undefined'.

5 ssl: process.env.PGSSLMODE && { rejectUnauthorized: false },


Thanks so much!

import { Pool, PoolConfig } from 'pg';


 export const pool = new Pool({
      connectionString: process.env.DATABASE_URL,
      ssl: process.env.PGSSLMODE && { rejectUnauthorized: false },

    })

 pool.on('connect', ()=> console.log('Postgres connected'))
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

From what the error indicates seems like you are using a string where a type 'boolean | ConnectionOptions | undefined' is expected Try this syntax instead

import { Pool, PoolConfig } from 'pg';


 export const pool = new Pool({
      connectionString: process.env.DATABASE_URL,
      ...( process.env.PGSSLMODE ? {ssl: { rejectUnauthorized: false }} : {}),
    })

 pool.on('connect', ()=> console.log('Postgres connected'))
about 4 years ago · Juan Pablo Isaza Relatório

0

If you interpret the log output it clearly states there is an issue is with the type which is expected and the type which you have declared.

The Expected type is, boolean or ConnectionOptions or undefined.

The Given type is, "" or { rejectUnauthorized: false; } or undefined

You need to assign a variable of the appropriate type or update the type of currently assigned variable.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda