Typescript is the language used for developing Javascript applications. I don't understand why new language was created instead of using matured and evolving language such as C#. C# could have been used for transpiling the code to Javascript. There are many third party and open source project which does this job. C# now supports closures, dynamic keyword, so transpiling C# to javascript would have been easy. From the syntax as well it also seems that Typescript is influenced from C#.
So questions is
Why Microsoft has developed a new language called Typescript instead of creating C# to Javascript transpiler? C# could have been used for the same purpose.
Is there any technical/other reason behind it?
Technically yes, but no. C#'s rules are extremely different than JavaScript's. They may look the same, but they are very far apart. (It's kinda like saying Java and JavaScript are the same, because they both use brackets, and they both start with Java.) TypeScript extends the JavaScript language. You can still write JavaScript in TypeScript. You couldn't do that if you used C#.
Here are some examples. In C# you can have multiple constructors. JavaScript (like Highlander) there can be only one.
C# allows method overloading. JavaScript....Nope.
JavaScript can have a variable number of parameters in a method call. You can have a method which takes 5 parameters and call it with 5, 4, 0, or 7 if you like. C# can't handle this.
Now you could generate JavaScript code from C#, but really you're just forcing the use of a subset of JavaScript to accommodate the use of C#. TypeScript is an entirely new language to work within the bounds of JavaScript, while providing some structure that strongly typed languages allow.
Typescript is a strict superset of Javascript, meaning almost all valid JS is also valid Typescript. It was made for interoperatibility with Javascript. C# could never be on the same level. Lots of different semantics that might not be immediatly obvious, but are definitely difficult.
Syntax might be similar, but the two languages are on a completely different level feature wise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With