简体   繁体   中英

vscode typescript intellisense for exported modules

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();

Going only on your uploaded images of code, in test.ts , I'd say you are trying to access a property on an async method. Instead use this syntax:

const test = new Editor();
const directus = await test.directus();
directus.propertyName

If this isn't correct and you update your question with the source code, I'll try to revise my answer.

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.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM