DEV Community

Discussion on: Is TypeScript Really... A Language??

Collapse
 
sancarn profile image
Sancarn

I didn't really wanna get into this level of "nerd-dom"

In order to answer the question "Is TypeScript really a programming language", you need to define what you mean by a programming language. I don't see this as nerdy. It's like asking "Is a cod an animal?" will always depend on the definition of what an animal is.

The syntax is different to JS so it cannot be seen as the same language as JS.

Is it really???

A syntax is made from a grammar. The grammar of TS and JS are different. E.G.

function greet(greeting: string): string {
   return greeting + " world";
}
Enter fullscreen mode Exit fullscreen mode

is not valid JavaScript. This is because types are not part of the JavaScript grammar. Because the grammar is seperate, the syntax is seperate and thus the languages are seperate. You wouldn't call C and C++ the same language just because their for loops look the same. C is very different to C++ even though they may act in similar ways.

Correct me if I'm wrong, but I don't believe it's possible to run TS without JavaScript, right??

You can, compile to WASM.

But if you've only learned TS, and one day, for some reason, someone said, "Hey... this particular thing must only be coded in plain-ol' JS," how long do you think it would take you to switch to base JavaScript? A day? A few hours, maybe? My contention is that the transition would be incredibly swift - because it's the same language.

The switch from Java to C# is virtually instant. Arguably more so than from TS to JS. That doesn't mean Java and C# are the same language though.

You're not embedding a JavaScript call inside of some static markup

I beg to differ. I'm not talking about what is actually hapenning under the hood. I'm talking about the semantics of the language. Like let's take a look at HTML:

<button onclick="console.log('hello world')"/>
Enter fullscreen mode Exit fullscreen mode

semantically can be seen as: <button onclick="EMBEDDED JS"/>

Similarly in jsx:

<button onclick={()=>console.log('hello world')}/>
Enter fullscreen mode Exit fullscreen mode

semantically this can be seen as: <button onclick={EMBEDDED JS}/>. Realistically JSX is embedding the JS (with the same syntax as plain JS) between the parenthesis {...}.

Don't get me wrong, HTML and JSX are still languages. They have their own syntaxes and semantics. The difference between them and languages like JS/TS/C/C++/C#/Java/Lolcode is that they merely produce templates, (or at least their common use is in creating templates).

JSX/HTML result in a template (or AST), it isn't generally seen as computing.

TS/JS result in a computed output.

It's a bit of a grey area, I'll give you that much as you might even be able to formulate a JSX expression which does compute, but as this is not its common/typical use case, I would argue it still can't be classified as a real programming language, akin to JS/TS.