Search code examples
javascripttypescriptlodashmonaco-editor

Adding Typescript Type Declarations to Monaco Editor


I have a Monaco editor which the user inputs custom javascript code. Within this Monaco Editor they can use Lodash functionality. I want to be able to give them the intellisense / code completion for lodash, by including the type definitions.

I've seen a few answers relating to adding custom declarations, but none that are including a whole 3rd party libraries declarations. Has anybody had experience with this.

This is what I have so far. Then below I create the editor, similar to the example in the documentation.

monaco.languages.typescript.typescriptDefaults.addExtraLib("", "./../../types/lodash/index.d.ts");

Solution

  • See this as an example and the apis. you should pass the content of the .d.ts file as the first argument

    monaco.languages.typescript.typescriptDefaults.addExtraLib(content, "")

    check this demo of how pass arguments