JavaScript has no problem, it sees an anonymous arrow function and it's .toString() method returns exactly that.
// This returns as expected
// ie `() => ""`
const t = [() => ""];
console.log(t[0].toString());
This example uses Babel, but the same happens in TypeScript. TypeScript sees an anonymous arrow function and tries to create an anonymous function statement which is invalid if trying to run eval on it.
// This returns an incomplete function string
const t = [() => ""]
console.log(t[0].toString());
Running eval(t[0].toString()) will return error:
SyntaxError: Function statements require a function name
Is there a way to preserve the correct syntax when using Babel/TypeScript? Is there some other better way of acheiving this?