Suppose you could use typescript and compile that?
Yes and no. Yes that's possible but no, this is no longer (full) TypeScript. Check AssemblyScript on that topic, it's TS to WASM. Most of the dynamic code stuff isn’t allowed and, of course, there’s a different standard library underneath.
Nothing is stopping you from compiling JavaScript though, browsers do it. The lack of static types makes this harder, of course.