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

109
Visualizações
typescript gives property is missing a type

I have a function with some default values, when I try to call the function and since it has some defaults so I do not need to pass in any values for defaults for example

function myFunc(
    {
      str1,
      str2,
      timeout = 3000,
    } : {
      str1: string,
      str2: string,
      timeout: number,
    }
  ): Promise<any | undefined> {
    // some logics here
  }


await myFunc({
      str1: 'string 1',
      str2: 'string 2'
  })

I get an error such as

Property 'timeout' is missing in type '{ str1: string; str2: string; timeout: number;}'

How can I resolve this since there is a default value declared, I shouldn't have to pass in the property if I don't need to override the default isn't it?

Thanks in advance for any help and suggestions.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This section is only JavaScript syntax:

function myFunc(
    {
      str1,
      str2,
      timeout = 3000,
    }

which will assign a value of 3000 if that parameter is undefined. You also need to indicate to TypeScript what the type of the parameter should be, and this:

{
      str1: string,
      str2: string,
      timeout: number,
}

requires timeout to be a property.

If you want it to be optional, note that in the TypeScript type as well, in addition to using the default value for the (emitted) JavaScript.

function myFunc(
    {
      str1,
      str2,
      timeout = 3000,
    } : {
      str1: string,
      str2: string,
      timeout?: number,
    }
  ): Promise<any | undefined> {
    // some logics here
  }
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