DEV Community

Cover image for Typescript
Karima Aktari
Karima Aktari

Posted on

Typescript

What is TYpescript:--

TypeScript is a strongly typed programming language which is built on JavaScript and developed and maintained by Microsoft. It is a syntactical superset of the JavaScript programming language. It’s an open source programming language. It is designed for the large applications development and transcompiles to JavaScript. It provides optional static typing, classes and interfaces. Typescript doesn’t run in the browser. The code which is written in typescript is compiled to JavaScript, then runs in the browser.

So, We can say that TypeScript is a strongly typed, object oriented, compiled language.

How Typescript works:--
Typescript has a relation with javascript. It offers all javascript features in its type system. JavaScript provides language primitives like string and number without checking that we’ve consistently assigned these but TypeScript does. Besides, typescript knows javascript and generates types for many cases.

Example:- If we create a variable and assign it to a particular value, TypeScript will use the value as its type.

Image description
Image description

Features of typescript:--

  • Browsers can’t compile typescript code, a compiler compiles typescript code into javascript and runs on browsers. That means the code of typescript is compiled to JavaScript for the purpose of execution.

  • TypeScript can run on any environment where JavaScript runs on.
    Typescript also supports other js libraries and JavaScript can also be written in TypeScript. Like:-
    i)Front-end in any framework ;
    ii) Backend in Node js ;
    iii) Cross-platform mobile apps in React Native ;

  • It supports OOP concepts like classes, objects, interfaces and inheritance etc.

  • Typescript is javascript and javascript is typescript because
    Typescript starts with Javascript and ends with JavaScript. And, as a superset of JavaScript any valid .js file can be renamed to .ts and compiled with other TypeScript files.

  • Typescript takes the basic building blocks of a program from JavaScript. So, we only need to know JavaScript to use TypeScript.

Difference between Typescript and Javascript:--

  • TypeScript checks a program for errors before execution but javascript doesn't.

  • JavaScript is dynamically typed. But Typescript provides optional static typing.

  • JavaScript is an interpreted single threaded programming language. It needs to be run to test and see if it is valid or not. But TypeScript transpiler provides the error-checking feature. Which helps to highlight errors before the script is run by compiling the code and generating compilation errors if there is any syntax error.

        Finally
    

Typescript isn't the altar of JavaScript, instead expanding it with new, valuable features. Everything that can be written in JavaScript can also be written in TypeScript.

Top comments (0)