Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Typescript compiles to js. Presumably you could have a typescript layer for this - but at that point it seems like your time would be better spent translating typescript to a compiled language than going ts -> js -> interpreter


sort by: page size:

TypeScript compiles to JS in a straightforward manner as well. If you wanted to move away from TS, you could simply have the TS compiler compile to ES6 and you're done.

Since typescript tsc can compile js, you could switch to using the typescript compiler to compile your javascript.

It would also detect some probable bugs in your js code.

Of course after a day or two you would start writing typescript and never look back.


You can embed any language interpreter into TypeScript and have that language syntaticaly checked by TS compiler.

You don't exactly need to compile Typescript to make it run, you can just strip the types out which is much faster than compilation. If you want you can run `tsc` to have the compiler compile it and check for errors, but this can be running as you develop to act more as a linter.

Suppose you could use typescript and compile that?

As far as I know there are no plans to directly compile (JIT or otherwise) typescript. Typescript is always (again, as far as I know) transpiled into javascript whereupon it gets JIT'd in the browser just like "normal" javascript.

The gains that come from using typescript are productivity gains: in big projects static typing, generics, decorators, and interfaces are supposed to be a boost to productivity, not a boost to performance.


I don't think so, since TS by definition compiles to JS. Too many embedded systems rely on JS. And many programmers, like me, prefer non-strongly-typed systems and/or runtime typing rather than compile-time.

Typescript is not a compiled language. It is a "transpiled" language. Transpiled to another interpreted language Javascript which in turn again is not a compiled language.

TypeScript has at least 2 implementations: tsc and Deno, but I take your point and agree. That said, most languages probably have a JS runtime, so a basic implementation would be ts->js->interpreter. The ts->js is presumably pretty easy.

Typescript usually transpiles to javascript, just without the type information, and this is not done in the browser. If you target old browsers it can add maybe add some overhead like babel does.

I don't know about javascript's usual JIT compilers, but LuaJIT's JIT compiler (trace compiler) does a pretty good job of figuring out abstractions.


I thought that TypeScript transpiles to JavaScript rather than compiles.

Can you compile TS from inside of JS or TS? something like `babel.transformFile`, that gives you back the compiled code?

Thanks ! But by compiled I meant compiled to binary, and I guess Typescript don't do it ?

TypeScript transpiles into some target JS version (ES5, ES6, ES2016, ES.Next). It is a different language but it gets executed as JS.

Typescript doesn't really transpile, kinda sorta...its output is idiomatic JS. It's syntax is basically just javascript. It's really just a natural way to annotate the types that you pass to javascript functions so that the compiler can check them. Not trying to be "that guy", just saying that it isn't like learning a whole new language. It's just adding a few things to the JS that you already know.

No TypeScript? Anywhere there is JS there is also TS, since it compiles to JS.

Any reason you can’t just use TS and compile to JS?

Isn’t typescript a superset of javascript so any ts compiler must also run js?

It's just compiling TypeScript into JS when you import it, and uses tsc to do it. It can load JS just fine as well if you want to use Babel or similar.
next

Legal | privacy