I got Pack Studio access!
To start, I’ve been hacking away on a little pack of date handling tools, and wanted to try a date range column format. I’m running into a Typescript bug, which has me a bit stumped as I’m not too familiar with TS. Here’s the column code (make sure to scroll):
const DateRangeSchema = coda.makeObjectSchema({
type: coda.ValueType.Object,
properties: {
startDate: {
description: "The beginning of the event or date range",
type: coda.ValueType.Number,
codaType: coda.ValueHintType.Date,
required: true,
},
endDate: {
description: "The end of the event or date range",
type: coda.ValueType.Number,
codaType: coda.ValueHintType.Date,
required: true,
},
}
})
pack.addColumnFormat({
name: "DateRange",
instructions: "An event spanning from a start date to an end date. Feed it a list of the start date and end date - e.g. ListCombine(StartDate, EndDate)",
formulaName: "DateRange",
formulaNamespace: "Deprecated", // Will be removed shortly
});
pack.addFormula({
name: "DateRange",
description: "Return a DateRange object from a list of the start date and end date",
parameters: [
coda.makeParameter({
name: "dates",
type: coda.ParameterType.DateArray,
description: "A list/array of the start and end dates",
}),
],
resultType: coda.ValueType.Object,
schema: DateRangeSchema,
execute: async function ([dates], context) {
return {
startDate: dates[0],
endDate: dates[1],
};
},
});
I get a red underline on execute
, and build fails with the following error referencing that line#:
Type '([dates]: ParamValues<[ParamDef<ArrayType<Type.date>>]>, context: ExecutionContext) => Promise<{ startDate: Date; endDate: Date; }>' is not assignable to type '(((params: ParamValues<[ParamDef<ArrayType<Type.date>>]>, context: ExecutionContext) => boolean | Promise<boolean>) & ((params: ParamValues<...>, context: ExecutionContext) => boolean | Promise<...>)) | (((params: ParamValues<...>, context: ExecutionContext) => number | Promise<...>) & ((params: ParamValues<...>, co...'. Type '([dates]: ParamValues<[ParamDef<ArrayType<Type.date>>]>, context: ExecutionContext) => Promise<{ startDate: Date; endDate: Date; }>' is not assignable to type '((params: ParamValues<[ParamDef<ArrayType<Type.date>>]>, context: ExecutionContext) => boolean | Promise<boolean>) & ((params: ParamValues<...>, context: ExecutionContext) => boolean | Promise<...>)'. Type '([dates]: ParamValues<[ParamDef<ArrayType<Type.date>>]>, context: ExecutionContext) => Promise<{ startDate: Date; endDate: Date; }>' is not assignable to type '(params: ParamValues<[ParamDef<ArrayType<Type.date>>]>, context: ExecutionContext) => boolean | Promise<boolean>'. Type 'Promise<{ startDate: Date; endDate: Date; }>' is not assignable to type 'boolean | Promise<boolean>'. Type 'Promise<{ startDate: Date; endDate: Date; }>' is not assignable to type 'Promise<boolean>'. Type '{ startDate: Date; endDate: Date; }' is not assignable to type 'boolean'.
If I hard code some integer values into the startDate
and endDate
properties of that last returned object, it works fine. What am I doing wrong here?