Here is the code snippet, I have written to calculate the no of days based on the two timestamp columns.
"
import { Function, FunctionsMap, Integer } from “@foundry/functions-api”
import { MaSchedule, ObjectSet } from “@foundry/ontology-api”
export class FnbackCol {
@Function()
public durationCalculator(schedule: ObjectSet): Promise<FunctionsMap<MaSchedule, Integer>>{
const map = new FunctionsMap<MaSchedule, Integer>();
schedule.all().forEach(sch => {
//function getDifference(sch.startTime: string, sch.endTime: string): Integer {
if (sch.startTime && sch.endTime) {
const start = new Date(sch.startTime);
const end = new Date(sch.endTime);
const diffInDays = Math.abs(end.getDate() - start.getDate());
map.set(sch, diffInDays as Integer);
} else {
map.set(sch, 0 as Integer)
}
});
return map
}
}
"
However, I am getting an compilation error at bold highlighted lines as below:
src/fnbackCol.ts(12,40): error TS2769: No overload matches this call.
Overload 1 of 4, ‘(value: string | number | Date): Date’, gave the following error.
Argument of type ‘Timestamp’ is not assignable to parameter of type ‘string | number | Date’.
Type ‘Timestamp’ is missing the following properties from type ‘Date’: toDateString, toTimeString, toLocaleDateString, toLocaleTimeString, and 29 more.
Overload 2 of 4, ‘(value: string | number): Date’, gave the following error.
Argument of type ‘Timestamp’ is not assignable to parameter of type ‘string | number’.
src/fnbackCol.ts(13,38): error TS2769: No overload matches this call.
Overload 1 of 4, ‘(value: string | number | Date): Date’, gave the following error.
Argument of type ‘Timestamp’ is not assignable to parameter of type ‘string | number | Date’.
Overload 2 of 4, ‘(value: string | number): Date’, gave the following error.
Argument of type ‘Timestamp’ is not assignable to parameter of type ‘string | number’.
src/fnbackCol.ts(20,9): error TS2739: Type ‘FunctionsMap<MaSchedule, number>’ is missing the following properties from type ‘Promise<FunctionsMap<MaSchedule, number>>’: then, catch, finally
src/schedule.ts(12,30): error TS2769: No overload matches this call.
Overload 1 of 4, ‘(value: string | number | Date): Date’, gave the following error.
Argument of type ‘Timestamp | undefined’ is not assignable to parameter of type ‘string | number | Date’.
Type ‘undefined’ is not assignable to type ‘string | number | Date’.
Overload 2 of 4, ‘(value: string | number): Date’, gave the following error.
Argument of type ‘Timestamp | undefined’ is not assignable to parameter of type ‘string | number’.
Type ‘undefined’ is not assignable to type ‘string | number’.
src/schedule.ts(13,28): error TS2769: No overload matches this call.
Overload 1 of 4, ‘(value: string | number | Date): Date’, gave the following error.
Argument of type ‘Timestamp | undefined’ is not assignable to parameter of type ‘string | number | Date’.
Overload 2 of 4, ‘(value: string | number): Date’, gave the following error.
Argument of type ‘Timestamp | undefined’ is not assignable to parameter of type ‘string | number’.
Kindly help me to resolve the issue.