(This question is a dupe: see here)
In this question we've already discussed how to run/evaluate a string representing TypeScript code, and the solution looks like:
import { transpile } from 'typescript';
const result = eval(transpile(stringRepresentingTypescriptCode));
My issue is that this does not help me detect TypeScript errors dynamically. The following code:
console.log(transpile('const str: string = 123;'));
outputs:
var str = 123;\n
My desired result is something like:
const str: string = 123;
^
TS2322: Type 'number' is not assignable to type 'string'
How can I evaluate a string representing TypeScript while also receiving type-related error information?