I wrote a game using coffeescript but I would have preferred to write it in typescript. The brute force way to resolve this is to convert the code by hand. But I'm wondering if there's a way to take the coffeescript or the javascript generated by coffeescript and convert it into typescript automatically. A man can dream.
JavaScript code is already TypeScript code. Although it may have type errors, the compiler will still output a file (when it says 'error' it really means 'warning' unless the error occurred during parsing, which shouldn't be the case for JS that actually runs).
In terms of converting idiomatic JavaScript class/module-like structures into TypeScript classes or modules, there aren't any tools for that (yet). The TFS Team wrote an internal bespoke tool for their codebase to do this, but that was only really possible because their JS was written under very strict rules to begin with.
This sounds like a bad idea. Even though they both produce JavaScript, CoffeeScript and TypeScript are very different. However, since TypeScript is a superset of JavaScript, the transpiled CoffeeScript is also valid TypeScript. From Wikipedia:
TypeScript is a superset of JavaScript. By default the compiler targets ECMA Script 3 (ES3) but ES5 is also supported as an option. A TypeScript application can consume existing JavaScript scripts. Compiled TypeScript scripts can be consumed from JavaScript.
And since you don't seem very committed to your "flavour of the week compiles to JS language" of choice why not actually write it in JavaScript? Just as an academic exercise?
© 2022 - 2024 — McMap. All rights reserved.