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

166
Visualizações
Date not working in Typescript but working in browser console

I get this error Supplied parameters do not match any signature of call target. when I try to do this in my TypeScript file in Angular2.

console.log(Date(this.field.sowing_date));

If I execute the same thing in the Chrome Debugger I don't get any problem.

Do you know what is?

I am using:

"@angular/core": "^2.4.0" "@angular/cli": "^1.0.0-rc.4", "@angular/compiler-cli": "^2.4.0",

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You cannot pass a parameter to Date when you don't use it as a constructor (without new):

In JavaScript:

Date(); // returns current date as string
Date("1/1/2017"); // ignores the parameter and returns the current date as string

TypeScript rightfully complains because Date(param) is not a valid way to call Date.

You can use Date in TypeScript like:

let currentDateAsString : string = Date(); // if you want the current date string
let parsedDate: Date = new Date(this.field.sowing_date); // if you want to parse it.

MDN documentation on Date which explains the ways Date can be used: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

over 4 years ago · Santiago Trujillo 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