Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hiroshinishio opened this issue Jan 24, 2022 · 2 comments

Comments

@hiroshinishio
Copy link

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?

@terryjiang2020
Copy link

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.

@khill-fbmc
Copy link

khill-fbmc commented Mar 30, 2023

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 {};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants