IntelliSense works as expected in my main project file where I imported a third-party library to my project;
Example: I'm using a library "Directus," however, when exporting the class and importing in another file in my project, IntelliSense stops working.
import { Directus } from '@directus/sdk';
export class Editor {
public async directus(): Promise<any> {
let directus = new Directus("http://localhost:8055/");
await directus.auth.login({
email: "email@admin",
password: "password",
});
return directus
}
}
When importing the class in another file test.ts (IntelliSense stops working)
I'm not sure if this is a vscode issue or typescript configuration problem.
import { Editor } from ".";
let test = new Editor();
CodePudding user response:
You are trying to access a property on an async method. Instead use this syntax:
const test = new Editor(); // create object instance
const directus = await test.directus(); // call method returning promise and await its value
directus.propertyName // access a property on the value
CodePudding user response:
Thanks to @jsejcksn for pointing out that I needed to await
for the method.
I have also needed to return the correct type, instead of using any
returning TypeMap
import { Directus, TypeMap } from '@directus/sdk';
export class Editor {
public async directus(): Promise<Directus<TypeMap>> {
let directus = new Directus("http://localhost:8055/");
await directus.auth.login({
email: "email@admin",
password: "password",
});
return directus
}
}
Now IntelliSense works as expected.