monaco editor: use d.ts files from node_modules for library auto completion

783 views Asked by At

I have installed a library @alfresco/js-api with npm.

I want to have auto completion for all types and functions defined in this library on monaco editor. I have manage to load all my d.ts files in addExtraLib().

    const files = require.context('!!raw-loader!/node_modules/@alfresco/js-api/typings/src/', true, /\.d.ts$/);
            
    files.keys().forEach((key: string) => {
      template += files(key).default;
      // We add every .d.ts file to Monaco
      monaco.languages.typescript.javascriptDefaults.addExtraLib(
        files(key).default,
        `file:///node_modules/@alfresco/js-api/typings/src/${key.slice(2)}`
      );
    });

In my d.ts files I have imports and module declarations.

But I have no autocompletion on monaco editor.

I manage to have autocompletion with a simple class declaration:

declare class ContentApi {
  getDocumentThumbnailUrl(nodeId: string, attachment?: boolean, ticket?: string): string;
}

I think the imports are the problem here, but I don't know how to make it work.

Any idea for solving this?

Thanks

0

There are 0 answers