My Zapier Hooks Pack recently broke for a few hours for something that TypeScript should have caught, but didn’t due to incorrect types or due to incorrect initialisation.
Here’s the formula coda:
pack.addFormula({
name: 'ZapierHook',
description: 'Trigger a Zapier Hook',
parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
name: 'url',
description: 'The Webhook URL of the Zapier Zap',
}),
coda.makeParameter({
type: coda.ParameterType.String,
name: 'body',
description: 'Body for a Zapier Catch Raw Hook',
optional: true,
}),
coda.makeParameter({
type: coda.ParameterType.StringArray,
name: "bodyParams",
description: "Body Params in the form of List(key, value, ...) for a Zapier Catch Hook",
optional: true,
}),
coda.makeParameter({
type: coda.ParameterType.StringArray,
name: "queryParams",
description: "Query/Search Params in the form of List(key, value, ...) for a Zapier Catch Hook",
optional: true,
}),
],
resultType: coda.ValueType.String,
isAction: true,
execute: async function ([where, body, bodyParamsList = [], queryParamsList = []], context) {
// ...
}
})
The issue is that optional StringArray params, such as:
coda.makeParameter({
type: coda.ParameterType.StringArray,
name: "bodyParams",
description: "Body Params in the form of List(key, value, ...) for a Zapier Catch Hook",
optional: true,
}),
Have their type set to string[]
instead of string[] | undefined
:
This then leads the pack author to assume that the param is pre-initialised by coda to an empty array (it isn’t) which can cause the pack to break as typescript won’t catch errors due to this mismatch (such as doing a .length
check on an undefined value).
Instead, what the pack author must do is initialise the param to an empty array:
execute: async function ([where, body, bodyParamsList = [], queryParamsList = []], context) {
So request here is for either the correct type to be returned, or for the variable to be initialised to the correct type.
Relevant pack code on github: