- Install the package to your project
npm install ts-simple-interpreter
- Import the
executeTS
method to js/ts componentThe return value will be the output of the executed result, similar to the output you would see in the console:import { executeTS } from 'ts-simple-interpreter'
const result = executeTS('your TypeScript code here'); console.log(result); // This will log the output of the executed code
Here’s a simple example demonstrating how to use the executeTS
method:
import { executeTS } from 'ts-simple-interpreter';
const tsCode = `
const add = (a: number, b: number): number => {
return a + b;
};
add(2, 3);
`;
const result = executeTS(tsCode);
console.log(result); // Expected output: 5