1

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",

4
  • You are not executing it. That is a type checking error. The code will still run. Commented Apr 28, 2017 at 13:19
  • Anyway, Date called as a function without an argument simply ignores it. That is why TypeScript is warning you that something is wrong. You have a bug. The code will always return a string representation of the current Date and Time Commented Apr 28, 2017 at 13:21
  • @AluanHaddad is with an argument this.field.sowing_date? Commented Apr 28, 2017 at 13:49
  • The argument is ignored at runtime. TypeScript raises an error for arity mismatches. Did you mean new Date(this.field.sowing_date)? Commented Apr 28, 2017 at 13:50

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.