Troubleshooting Typescript Error

Hello, I am making a pack that was building successfully for over a dozen versions, but is now failing on a Typescript error that I am having a hard time troubleshooting. Can anyone help with this?

The error is on the execute section of the code block shown below:

import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack(); 


pack.addNetworkDomain("pagerduty.com");

pack.setUserAuthentication({
  type: coda.AuthenticationType.OAuth2,
  authorizationUrl: "https://identity.pagerduty.com/oauth/authorize",
  tokenUrl: "https://identity.pagerduty.com/oauth/token",
  scopes: ["incidents.read"],
  useProofKeyForCodeExchange: true,
});

// Define incident schema
const IncidentSchema = coda.makeObjectSchema({
  properties: {
    title: {
      description: "The name of the incident.",
      type: coda.ValueType.String,
      required: true,
    },
    description: {
      description: "A detailed description of the incident.",
      type: coda.ValueType.String,
    },
    created_at: {
      description: "The date the incident was created",
      type: coda.ValueType.String,
      codaType: coda.ValueHintType.DateTime,
    },
    id: {
      description: "The ID of the incident.",
      type: coda.ValueType.String,
    },
    service: {
      description: "The service of the incident.",
      type: coda.ValueType.String,
    },
    escalation_policy: {
      description: "The escalation policy of the incident." ,
      type: coda.ValueType.String,
    },
    priority: {
      description: "The severity of the incident." ,
      type: coda.ValueType.String,
    },
    html_url: {
      description: "The url of the incident." ,
      type: coda.ValueType.String,
      codaType: coda.ValueHintType.Url
    },
  },
  displayProperty: "title",
  idProperty: "id",
  featuredProperties: ["title", "description", "created_at", "service", "priority", "html_url"]
});

// Sync incident schema
pack.addSyncTable({
  name: "IncidentList",
  description: "Pull all incident information",
  identityName: "IncidentList",
  schema: IncidentSchema,
  formula: {
    name: "IncidentList",
    description: "Export incident details for a given timeframe, status and service",
    parameters: [],
    
    execute: async function ([IncidentList], context) {
      let url = coda.withQueryParams("https://api.pagerduty.com/incidents");

      let response = await context.fetcher.fetch ({
        method: "GET",
        url: url,
        headers: {
          "Accept": "application/vnd.pagerduty+json;version=2",
          "Content-Type": "application/json",
        },
      });

let results = response.body.incidents;
      return {
        title: results.title,
        description: results.description,
        created_at: results.created_at,
        id: results.id,
        service: results.service.summary,
        escalation_policy: results.escalation_policy.summary,
        priority: results.priority.summary,
        html_url: results.html_url,
      };
    }
  }
  });

Here is the error:

On line 70 Type '([IncidentList]: [any], context: any) => Promise<{ title: any; description: any; created_at: any; id: any; service: any; escalation_policy: any; priority: any; html_url: any; }>' is not assignable to type '{ (params: ParamValues<[]>, context: SyncExecutionContext): Promise<SyncFormulaResult<string, string, { properties: { title: { description: string; type: ValueType.String; required: true; }; ... 6 more ...; html_url: { ...; }; }; displayProperty: "title"; idProperty: "id"; featuredProperties: ("description" | ... 4 ...'. Types of parameters '__0' and 'params' are incompatible. Property '0' is missing in type '[] & any[]' but required in type '[any]'.

Any help you can offer would be greatly appreciated!

Hi @Adam_Weir1 - Those TypeScript errors can be quite mysterious sometimes! I can see two issues with your sync table:

  1. It declare any parameters, but it trying to unpack one in the execute function:

    pack.addSyncTable({
      // ...
      formula: {
        // ...
        parameters: [],
        
        execute: async function ([IncidentList], context) {
          // ...
    

    You either need to declare a parameter to match IncedentList or you need to remove that from the execute function.

  2. You aren’t returning the the rows in the correct format:

    pack.addSyncTable({
      // ...
      formula: {
        // ...
        execute: async function ([IncidentList], context) {
          // ...
          return {
            title: results.title,
            description: results.description,
            // ...
          };
    

    When returning a set of rows from the execute function of a sync table you need to return data in the shape:

    return {
      result: arrayOfRows,
      continuation: continuationObjectMaybe,
    };
    

    You seem to be returning a single row, and now nested in an outer object.

Let me know if that helps at all.

2 Likes

Hi Eric, that does help! Here are the changes I have made:

  1. remove parameters from execute function: this allowed me to build again
  2. return rows in the correct formate: I reshaped this section to return the rows in an array like so:
let results = response.body.incidents;
      return {
            results.title,
            results.description,
            results.created_at,
            results.id,
            results.service.summary,
            results.escalation_policy.summary,
            results.priority.summary,
            results.html_url,
      };

But now I am getting the following errors:

  1. cannot parse summary. I am looking to get the summary of those json objects because that is the human readable section. Is there a better way to return that part of the response?
  2. New error when trying to refresh the table in my doc: Syncing Incident list from PagerDuty failed - 'id' property is undefined or null

Any more help you can provide would be greatly appreciated!

Actually, since posting my last comment I got it (mostly) working. Using your Cats sample pack, of all things!

I am still left with error #1 above though - I want the summary attribute within the JSON objects service, escalation_policy, and priority. But the %.summary added to each of them throws an error. When I read them into the doc and hover over the object chip, I see the information there but cant parse it.

Is there another way to write the results that would let me access that information? Do I need to add row reference sync tables for each of them?

I think the issue may be that you aren’t making sure the keys match between the schema and the result object. Make sure that the key of the left side of the schema property matches the key on the left side of the returned object. To troubleshoot further I’d suggest booking some time during office hours: