TypeScript
TypeScript is a programming language developed and maintained by Microsoft. TypeScript is a language for application-scale JavaScript. In other words Typescript is a typed superset of JavaScript and was created by Microsoft in 2012 to aid Javascript developers with large-scale applications. Typescript was designed to help as a structuring mechanism for large codebases because it helps avoid common errors that would slow us down.
TypeScript makes it easier for teams to work on the same project, as the language allows for modification and produces readable code. If there are multiple developers working on one project, Typescript can help us to prevent a lot of wasted time on debugging. TypeScript language allows us to use our Javascript skills more effectively. In fact, after we compile your code, all the Typescript stuff goes away and produces clean, cross-platform safe Javascript code. On top of being interoperable, Typescript adds unique features, including static typing, interfaces, classes, and more.
TypeScript can be used to develop JavaScript applications for both client-side and server-side execution (as with Node.js
or Deno
). TypeScript supports definition files that can contain type information of existing JavaScript libraries, much like 'C++ header files' and can describe the structure of existing object files. This enables other programs to use the values defined in the files as if they were statically typed TypeScript entities. The TypeScript compiler is itself written in TypeScript and compiled to JavaScript.
TypeScript is licensed under the Apache License 2.0
.
Why should we use Typescript?
There are many important benefits to using Typescript. Typescript catches mistakes in our JavaScript code earlier on. Typescript has the ability to catch bugs and errors before runtime, so that we are able to write reliable code and mitigates the pitfalls of JavaScript that are only found at runtime. Some of the major benefits of using TypeScript is written below:-
- Transpiling allows you to generate ECMAScript and also we can specify which version of JavaScript we prefer to use. This means that we can write code that is compatible with old browsers, all while using the newest tools.
- Typescript supports JS libraries and API documentation, including JQuery, BootStrapJS, React, and more and thus we can use all the familiar tools we already know.
- Typescript uses NPM, which gives us access to millions of reliable libraries. This also makes it far easier to learn Typescript, as we don’t have to make custom tools to access libraries.
- Typescript is easier to maintain. The language is generally easier to read and access. The built-in self-documentation makes it easier to check on types and objects in our code.
- Typescript makes it easier to use React, Angular, and Vue. Typescript integrates well with these frameworks, particularly React, which has been described as a perfect fit with Typescript.
TypeScript development tools:
- IDE and editor support - There are many IDE's where we can write down our TypeScript code, format or debug it. Visual Studio Code is a (mostly) open-source, cross-platform source code editor developed by Microsoft based on Electron. It supports TypeScript in addition to several other languages, and offers features like debugging and intelligent code completion. Atom has a TypeScript Plugin by `Basarat` with support for code completion, navigation, formatting, and fast compilation. JetBrains supports TypeScript with code completion, refactoring and debugging in its IDEs built on IntelliJ platform.
- Compiler - The TypeScript compiler, named tsc, is written in TypeScript. As a result, it can be compiled into regular JavaScript and can then be executed in any JavaScript engine (e.g. a browser). The compiler package comes bundled with a script host that can execute the compiler. It is also available as a Node.js package that uses Node.js as a host.
- Integration with build automation tools - Using plug-ins, TypeScript can be integrated with build automation tools, including Grunt, Apache Maven, Gulp and Gradle.
- Linting tools - TSLint scans TypeScript code for conformance to a set of standards and guidelines. ESLint, a standard JavaScript linter, also provides some support for TypeScript via community plugins.
Installing:
For the latest stable version:
npm install -g typescript
For our nightly builds:
npm install -g typescript@next
Cons of using TypeScript:
- TypeScript takes a long time to compile the code.
- TypeScript doesn’t support abstract classes.
- Whenever TypeScript needs to run in a browser, there must still be a compilation step to transform TypeScript to JavaScript.
- TypeScript is not fully coexpressive with JavasScript. Missing features include: HOFs, Composition, Generics with Higher Kinded Types, etc
Contributing:
There are many ways through whch we can contribute to TypeScript.
Submit bugs and help TypeScript to verify fixes as they are checked in.
Review the source code changes.
Engage with other TypeScript users and developers on StackOverflow.
Help each other in the TypeScript Community Discord.
You can join the #typescript discussion on Twitter.
Read the archived language specification (docx, pdf, md).
References:
TypeScript Github: https://github.com/microsoft/TypeScript
TypeScript Docs: https://www.typescriptlang.org/docs/
Educative.io Blog: https://www.educative.io/blog/typescript-tutorial
Tutorialspoint Docs: https://www.tutorialspoint.com/typescript/index.htm