Provide type hints to monaco editor

后端 未结 3 2094
耶瑟儿~
耶瑟儿~ 2021-02-10 12:34

I am trying to provide intellisense / code completion into a javascript editor using the Monaco editor. The code needs to be valid javascript, not typescript.

Given some

3条回答
  •  深忆病人
    2021-02-10 13:10

    Put this in the editor in the Monaco Playground:

    monaco.editor.create(document.getElementById("container"), {
        value: "function hello() {\n\talert('Hello world!');\n}",
        language: "typescript"
    });
    
    const fact = `declare function onMyEvent(event: string): void; 
    `;
    const factFilename = 'myCustomNamespace1';
    this.monaco.languages.typescript.typescriptDefaults.addExtraLib(fact, factFilename);
    

    Now when you type onMyEvent in the right-hand pane, you'll get

提交回复
热议问题