For some unknown reason, I need to utilize the eval() function and access a specific function called foo
. Unfortunately, I am struggling to achieve this in TypeScript.
eval("function foo() { console.log(\"foo bar\") }");
// @ts-ignore
foo();
Instead of printing "foo bar" in the console log, the code above throws an error.
VM42:4 Uncaught ReferenceError: foo is not defined
You can experiment with the code snippet here.
However, the same code works perfectly fine in JavaScript.
Do you think additional configuration is needed?