Are there any engines to execute TypeScript code directly?

When I first studied TypeScript, I found that node.js doesn’t execute TypeScript, so you need to install a TypeScript compiler that converts your TypeScript code into JavaScript.

I searched until I found ts-node (TypeScript execution and REPL for node.js), but when I read the documentation I found that they do the same (here). Even deno (A modern runtime for JavaScript and TypeScript), is doing the same (here).

So my question is: are there any engines to execute TypeScript code without converting it to JavaScript?

>Solution :

No, TypeScript is not a "standalone" language in that sense. It is and always will be a superset of JavaScript. This is why the TypeScript Compiler is often referred to as a transpiler: it doesn’t compile to a lower-level language. After tsc has run its checks it transforms existing source to JavaScript by simply stripping out all the TypeScript constructs.

From the intro of the official TypeScript Handbook:

The goal of TypeScript is to be a static typechecker for JavaScript programs – in other words, a tool that runs before your code runs (static) and ensures that the types of the program are correct (typechecked).

So in order to execute TypeScript, you will always need a JavaScript engine. You could adapt an existing JavaScript engine (or build your own) to understand TypeScript as well, but still it would always first have to be an engine conforming to the ECMAScript specification.

Leave a Reply