0

I have written a code to calculate the today's date

function today() {
   const now = new Date();
   const monthday = ("0" + now.getDate().toString()).slice(-2);
   const month = ("0" + (now.getMonth() + 1).toString()).slice(-2);
   const year = now.getFullYear();

   return `${monthday}.${month}.${year}`;
}

I am accessing this with name 'today' to check if the present date exists , but failing to do so

await _assertExists(_cell(today, _under(_tableHeader("Calculate"))

Error is as below

semantic error TS2345: Argument of type '() => string' is not assignable to parameter of type 'AccessorIdentifier'. Type '() => string' has no properties in common with type 'Partial<AccessorIdentifierAttributesWithClassName & AccessorIdentifierAttributesWithSahiIndex & AccessorIdentifierAttrbutesWithText>

Greg
  • 5,862
  • 1
  • 25
  • 52
JBOSSUSER
  • 35
  • 9
  • What's `_cell` definition? Does it expect a string as the first parameter? It looks like it expects `AccessorIdentifier` and not a String. – Greg Jun 17 '21 at 09:52
  • _cell is itself a accessor identifier and it expects a string – JBOSSUSER Jun 17 '21 at 09:55
  • 2
    Try this: `await _assertExists(_cell(today(), _under(_tableHeader("Calculate"))` the () after the name `today` tell typescript that today is a fonction to execute – Lautre Jun 17 '21 at 10:12
  • 1
    To see the difference between `today` and `today()` use a console.log(). `console.log(today)` will display the definition of the function. `console.log(today())` will display the data returned by the function – Lautre Jun 17 '21 at 10:14

0 Answers0