Trying to build typescript code in JS so i can display on UI for user to play with the code , is there a way to create this code as a typescript instead of text so it compile as well ? Any help here will be highly appreciated couldn't find any source related to this issue.
data
contains interfaces
main.js
function buildTypescript(data) {
var _ref = window.activeOperation;
var modelData = getModelData(data);
var text = '';
text += "import {Api as IngenSDK} from '@SSDK'" + ';\n\n';
text += modelData;
text += 'app.Api.setConfig({\n "env": "SIT3"\n});\n\n';
text += _ref + '(' + JSON.stringify(SDKresult[_ref].request, null, 4) + ', function(result) {\n //Your code goes here \n debugger; \n console.log(result); \n});';
$('#request_method_TS').text(text);
}
function getModelData(data){
var activePath = window.activePath.toLowerCase();
var _interface;
$.each(data.children, function(id, item){
// item.name would be string like "@SDK/core/interface/member/Details";
var path = item.name.replace(/\"/g, "");
if (path.toLowerCase().includes(activePath)) {
console.log('OBJ', item);
_interface = createInterfaces(path,item.children);
}
});
return _interface;
}
function createInterfaces(path, data) {
const imports = data.map(d => d.name).join(', ');
return `import { ${imports} } from '${path}';\n\n`;
}
html
<pre id="request_method_TS" style="margin: 5px;"></pre>