Ready to commit crimes™ against your type system? Look no further than js-in-ts, the worlds first (probably (hopefully)) JavaScript interpreter written in TypeScript's type system!
What.
import { Eval } from "../utils";
const factorial = <N extends number>(limit: N): Eval<`
(limit) => {
let rec = (val) => {
if (val > limit) {
return 1;
}
return val * rec(val + 1);
};
return rec(1);
}
`, [N]> => {
let rec = (val: number) => {
if (val > limit) {
return 0;
}
return val * rec(val + 1);
};
return rec(1) as any;
}
yarn add jsits
Blood, sweat, and arcane magiks. For full details, check out this writeup:
Yeah, go for it! Just try not to make it too imperformant that the demos fail.
Zach Wade [email protected] (@zwad3)