Provide type hints to monaco editor

后端 未结 3 2103
耶瑟儿~
耶瑟儿~ 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条回答
  •  旧时难觅i
    2021-02-10 13:02

    This is how we do it for magikcraft.io: drop this code straight into the left pane in the playground, then hit Run:

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

    Now, in the right pane, then type: custom. and you'll get autocomplete for the custom facts.

提交回复
热议问题