Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript vs JSX [closed]

I'm somewhat familiar with TypeScript and have recently been made aware of JSX. They both seem to be similar to me. I looked at the comparison to JSX on this website and they compared it to Dart and some other technologies but not to TypeScript.

TypeScript and JSX appear to both compile to JavaScript and provide static typing and classes, but they seem to be complementary and not competitors according to a few places on the web such as TypeScript and JSX.

I'm trying to make this not too open ended, so can someone tell me what features TypeScript offers that JSX doesn't and vice versa?

like image 591
Eric Avatar asked Nov 03 '16 20:11

Eric


People also ask

Is JSX the same as TypeScript?

TypeScript is a language that is a syntactic-superset of JavaScript. JSX is FaceBook's XML-like syntax extension to JavaScript, not a language per se.

Does React use TypeScript or JSX?

Though many other frameworks and libraries adopt TypeScript by default, React remained neutral, giving the developers the option to choose between TypeScript and JavaScript.

Does JSX use TypeScript?

TypeScript supports embedding, type checking, and compiling JSX directly to JavaScript.

What is the difference between TSX and JSX?

. tsx is similar to jsx except it's TypeScript with the JSX language extension.


2 Answers

The original answer is insufficient and not up to date with the current standards.

JSX is NOT a language. It's NOTHING BUT Javascript but with a different extension. Facebook came up with this new extension so that they can demarcate the XML-like implementation of HTML in JavaScript. In early versions of React, this extension was mandatory for writing HTML inside JavaScript. However, this restriction was removed a few years ago which basically meant that there is no difference at all in JS and JSX. (Using only .js extension is the standard norm nowadays BTW)

Coming to TypeScript, it is a SUPERSET of JavaScript which adds extra functionalities to plain JavaScript making the applications more robust. Watch this video for better understanding of TypeScript: https://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing-TypeScript

To conclude, JSX = JS, typescript is a superset of Javascript, and there is no comparison between JSX and TypeScript.

like image 191
saran3h Avatar answered Oct 02 '22 22:10

saran3h


I will try to give you a brief answer. In my experience, something great about TSX is that it will avoid some errors immediately, it has static typing, it is easy to maintain and you can use OPP (Yes, similar to Java). JSX is very similar to JS, you don't have to define the type of data (dynamically typed), a lot of freedom and easy to understand.

like image 43
dotconde Avatar answered Oct 02 '22 22:10

dotconde