DEV Community

Cover image for TypeScript
Sanni_Damilola
Sanni_Damilola

Posted on

TypeScript

Typescript (also known as ECMAScript) started its life as a simple scripting language for browsers. At the time it was invented, it was expected to be used for short snippets of code embedded in a web page - writing more than a few dozen lines of code would have been somewhat unusual. Due to this, early web browsers executed such code pretty slowly. Over time, though, JS became more and more popular, and web developers started using it to create interactive experiences.
Furthermore, Typescript won't allow any errors, more so, it would be difficult to learn TypeScript without learning JavaScript! TypeScript shares syntax and runtime behavior with JavaScript, so anything you learn about JavaScript is helping you learn TypeScript at the same time.
Roughly speaking, once TypeScript's compiler is done with checking your code, it erases the types to produce the resulting "compiled" code. This means that once your code is compiled, the resulting plain JS code has no type of information.
This also means that TypeScript never changes the behavior of your program based on the types it inferred. The bottom line is that while you might see type errors during compilation, the type of system itself has no bearing on how your program works when it runs.
Finally, TypeScript doesn't provide any additional runtime libraries. Your programs will use the same standard library (or external libraries) as JavaScript programs, so there's no additional TypeScript-specific framework to learn.
I said earlier that typescript wouldn't allow those buggy programs to run at all. Detecting errors in code without running it is referred to as static checking. Determining what's an error and what's not based on the kinds of values being operated on is known as static type checking.
TypeScript checks a program for errors before execution, and does so based on the kinds of values, it's a static type of checker.
To summarize, typescript catches 50% of bugs. TypeScript is JavaScript's runtime with a compile-time type checker. The way you use a method in TypeScript is the same way you do so in JavaScript.

Top comments (4)

Collapse
 
aarone4 profile image
Aaron Reese

Almost every statement in your article is incorrect. You have failed this module in your bootcamp. Please go back and review your source materials.
Typescript is not ECMAScript. Typescript is a superset of JS but cannot be run in the browser; it requires a transpiler to convert it to JS. Typescript allows you to define types for variables and will indicate (via IDE plugins) when the type passed in does not match the expected type. At no time will it actually prevent code from compiling or running, nor will it ensure that the types used at runtime match those defined at design time.

Collapse
 
sannidamilola profile image
Sanni_Damilola

Do you have any recommendations for me?
@aarone4

Collapse
 
aarone4 profile image
Aaron Reese

The article reads like it was a homework assignment for a bootcamp so my apologies for this assumption if it is incorrect. As I said in my original reply, most of the article is factually incorrect and I get the imporession you have failed to grasp the history of JS and the current state of TS, IDE plugins and the compile/transpile process. If you tutors are letting you get away with the incorrect assumptions they are setting you up for a fall.

I would reccomend some on free or cheap line courses on Udemy or YouTube. Anyting by FreeCodeCamp org or Max Schwartzmuller will see you right.
Although it is not a requirement to fully understand the intricacies of TS and JS to be able to develop in them, your assertions are generally incorrect and I was just highlight that fact for future readers.

Thread Thread
 
sannidamilola profile image
Sanni_Damilola

okay thanks