Skip to content

Right way to add type definitions for intellisense throught addExtraLib? #1415

@bochkovyi

Description

@bochkovyi

After days and hours of searching, I have to ask the community for help.

Right now I found two ways of adding type definitions to monaco editor.

  1. first way
    monaco.languages.typescript.typescriptDefaults.addExtraLib( DTSFileContent, 'file:///node_modules/@types/your-file-path.d.ts')

  2. second way
    monaco.languages.typescript.typescriptDefaults.addExtraLib(declare module "${lib.name}" { ${DTSFileContent } }, lib.name);

i have several issues with these two approaches.

  1. adding libs in a first manner does not allow to create lib path like "@angular/core", while "angular/core" is possible
  2. i was not able to find a way for loading d.ts files that reference other libs. Example - barrel d.ts files for angular. those references are not taken into account.

I could just say it's not possible - but it is.
Look at stackblitz. https://stackblitz.com/edit/angular-3ccygq
Inside browser console type and you'll see this.
monaco.languages.typescript.typescriptDefaults._extraLibs

image

Somehow it's possible to add libraries that reference each other. But not able to replicate that in monaco-template.

Any idea?
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions