node-asana icon indicating copy to clipboard operation
node-asana copied to clipboard

"Property 'getTasks' does not exist on type 'Tasks'. Did you mean 'getTask'?" but WHY??

Open hiroshinishio opened this issue 3 years ago • 2 comments

Code is here, probably not complex. This code is just hitting the API to get the tasks of a certain worker in a certain workspace in Asana.

import asana from "asana";

const GetAsanaData = () => {
  const personalAccessToken = `Bearer 1/1200...`;
  const workspace = "1200...";
  const assignee = "12007...";
  const opt_fields = ["name", "completed", "completed_at"];

  const client = asana.Client.create().useAccessToken(personalAccessToken);
  const result = client.tasks
    .getTasks({
      workspace: workspace,
      assignee: assignee,
      opt_fields: opt_fields,
    })
    .then((response) => response);
  return result;
};

export default GetAsanaData;

First error says;

Could not find a declaration file for module 'asana'. 'C:/Users/81906/Documents/polygon-hr/node_modules/asana/index.js' implicitly has an 'any' type. Try npm i --save-dev @types/asana if it exists or add a new declaration (.d.ts) file containing declare module 'asana';ts(7016)

Then I followed this error and then second error happens and says;

Property 'getTasks' does not exist on type 'Tasks'. Did you mean 'getTask'?ts(2551) index.d.ts(2060, 13): 'getTask' is declared here.

Indeed, if I looked at the referenced index.d.ts(2060, 13), there are no getTasks instead of getTask. However, the official documentation (https://developers.asana.com/docs/get-multiple-tasks) says to call it this way... Is it a bug in the library?

hiroshinishio avatar Jan 24 '22 11:01 hiroshinishio

It is probably a typo or outdated content in the doc. The same thing happens to webhook-related content. For anyone who is struggling with the doc, I think at the moment you might need to find the way out by viewing the code inside the module rather than keep reading docs.

terryjiang2020 avatar Oct 14 '22 20:10 terryjiang2020

I would like to chime in too since I have been deep in this...

ASANA PLEASE FIX! Or how can I help???

There is a huge gap between what the docs show and what the module types hint in my editor. I created this hacky stub for myself to get rid of errors, but I feel like each example I grab needs me to fix it up 😞 This works for me for now...

import type asana from "asana";

declare module "asana" {
  namespace resources {
    interface Tags {
      /**
       * This is barely a stub and incomplete
       */
      getTagsForWorkspace(workspaceGid: string): Promise<AsanaBaseApiResponse<asana.resources.Tags.Type>>;
    }

    interface Tasks {
      getSubtasksForTask(taskGid: string): Promise<AsanaBaseApiResponse<asana.resources.Tasks.Type[]>>;
      /**
       * This is barely a stub and incomplete
       */
      getTasksForProject(project: string, params?: Params): Promise<AsanaBaseApiResponse<asana.resources.Tasks.Type[]>>;
    }

    interface Stories {
      /**
       * @link https://developers.asana.com/reference/createstoryfortask
       */
      createStoryForTask(
        taskGid: string,
        data:
          | {
              html_text: string;
              is_pinned?: boolean;
              sticker_name?: string | null;
            }
          | {
              text: string;
              is_pinned?: boolean;
              sticker_name?: string | null;
            }
      ): Promise<AsanaBaseApiResponse<resources.Stories.Type>>;
    }

    interface Webhooks {
      createWebhook(def: {
        resource: string;
        target: string;
        filters?: asana.resources.Webhooks.Filter[];
      }): Promise<asana.resources.Webhooks.Type>;
    }
  }
}


export interface AsanaBaseApiResponse {
  status: number;
  value: unknown;
}

export interface AsanaApiError {
  message: string;
  help: string;
  phrase: string;
}

export interface AsanaSuccessResponse<T = unknown> extends AsanaBaseApiResponse {
  status: 200;
  value: T;
}

export interface AsanaErrorResponse extends AsanaBaseApiResponse {
  status: 400 | 401 | 402 | 403 | 404 | 500;
  value: {
    errors: AsanaApiError[];
  };
}

export type AsanaApiResponse<T = unknown> = AsanaSuccessResponse<T> | AsanaErrorResponse;

export {};

khill-fbmc avatar Mar 30 '23 12:03 khill-fbmc