Issue: I am in need of assistance to convert a typescript model that utilizes intellisense from extraLibs (an option in the monaco editor) into a JSON object. This JSON object will then be sent to an API for processing.
Here is the code snippet that you can paste into the Monaco Editor Playground for further testing
// extra libraries
monaco.languages.typescript.typescriptDefaults.addExtraLib('enum Types {type1 = 1,type2 = 2} interface Page {name: string;type: Types;}', 'ts:filename/facts.d.ts');
var jsCode = `
// This is a typescript model that users can modify in the monaco editor
var model: Page = {
name: "Page",
type: Types.type1
}
// I require the above typescript model in JSON format to send it to an API as illustrated below
/*
{
"name": "Page",
"type": 1
}
*/
`;
monaco.editor.create(document.getElementById("container"), {
value: jsCode,
language: "typescript"
});
// Exploring some functionality
monaco.languages.typescript.getTypeScriptWorker().then(x => {
x('').then(y => {
y.getEmitOutput('hello').then(z => {
console.log(z)
});
})
})
Important Note: I am currently working with Angular