Asana/node-asana

Property 'ApiClient' does not exist on type 'typeof asana'. Did you mean 'Client'?ts(2551)

Opened this issue ยท 5 comments

Types don't really match the code

Hi @Strooss which version of the node-asana are you using? In our v1.X.X (EX:v1.0.5) you would use asana.Client while in v3.X.X [EX: v3.0.6] it's Asana.ApiClient

node-asana v1.0.5:

const asana = require('asana');

const client = asana.Client.create().useAccessToken("<YOUR_ASANA_PERSONAL_ACCESS_TOKEN>");

client.users.getUser("me").then((result) => {
    console.log(result);
});
v1_sample_code

node-asana v3.0.6:

const Asana = require('asana');

let client = Asana.ApiClient.instance;
let token = client.authentications['token'];
token.accessToken = "<YOUR_ASANA_PERSONAL_ACCESS_TOKEN>";

let usersApiInstance = new Asana.UsersApi();
let user_gid = "me"; // String | A string identifying a user. This can either be the string \"me\", an email, or the gid of a user.
let opts = {};

usersApiInstance.getUser(user_gid, opts).then((result) => {
    console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2));
}, (error) => {
    console.error(error.response.body);
});
v3_sample_code

@Strooss the @types/asana package matches the types in the previous version of asana.

npm remove @types/node
rm -rf node_modules
npm install

then restart your editor, and the type issues should disappear. Sadly you'll have no types ๐Ÿ˜ž

Yes im using the last version (node-dsk-v3). and yes the package don't have types right?

Hi @Strooss, @oev-chrisbennett is correct.

The @types/asana package only works with node-asana v1 client library version.

node-asana v3 client library version is not supported.

For context, we did not write or maintain the @types/asana package. It looks like an external dev worked on this and had to manually maintain it by updating it when our API changes.

Taking a look at the commit history for @types/asana it looks like the last major update to the types was 2 years ago.

I see, that you have a lot of jsdocs in the source, which should enable typescript to create types while using this lib.
However, it's not working for me. any ideas?