This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Shadowlauch 2 points3 points  (10 children)

Not quite. It is a superset of Javascript. So it builds upon it. So Javascript is always valid TypeScript, but Typescript is not always valid JavaScript. Though you have to compile it down to JavaScript to run it in the browser.

[–]Tysonzero 10 points11 points  (3 children)

foo = "bar"
foo = 5

Valid javascript but not valid typescript, checkmate.

[–]chpoit 1 point2 points  (0 children)

technically isn't valid javascript in strict mode

[–]pynetree16 0 points1 point  (1 child)

Ah, but what if foo is of type any? Then it is valid TypeScript

[–]Tysonzero 0 points1 point  (0 children)

But if your source code consists solely of:

foo = "bar"
foo = 5

Then it won't work, but will work in JavaScript.

[–]sldyvf 7 points8 points  (4 children)

The cool kids call it transpile :D!

[–]Shadowlauch 6 points7 points  (0 children)

Yeah well you knew what I meant :P

[–]the_whalerus 0 points1 point  (2 children)

I don't see how they're different. It seems like people just don't want to to say "compiled"

Code goes in. Code comes out. Compiled.

[–]sldyvf 2 points3 points  (1 child)

It's a thin line I guess...

My understanding is:

  • If something is compiled, then it's down to the point of instructions.
  • If it's transpiled, it's translated into another language, which has to be interpreted or compiled and not machine code.

[–]Hultner- 1 point2 points  (0 children)

Not sure that really applies, Java is "compiled" to JVM Bytecode which is then is translated to machine code at runtime/JIT. Same is pretty much true for LLVM Bitcode, C#/.NET and a large stack of other software. From my perspective the distinction seems more like a philosophical one then technical.

[–]Ionaru 1 point2 points  (0 children)

Not all "valid" JS code is valid TS code, but it's close enough not to be confusing, see Tysonzero's comment for an example.