Author : MD TAREQ HASSAN | Updated : 2020/10/26
What is TypeScript?
- Superset of JavaScript
- a strict syntactical superset of JavaScript and adds optional static typing to the language
- a typed superset of JavaScript that compiles to plain JavaScript
- Open-source programming language developed and maintained by Microsoft
- Designed for development of large applications
Overview
Benefits of TypeScript
- Static types: variables, parameters, return types etc.
- Organization: class module, namespaces, interfaces
- Tooling: static analysis, instant errors, detect unused/unreachable code etc
Static analysis
Static analysis means that regardless of whether you explicitly define types or not, TypeScript looks through your code, doing its best to guess or infer what type any given object could be.
In other words, even though this is just plain old JavaScript, just using the code that is written, TypeScript is able to figure out that the type of the properties are strings/int/bool etc. and the abc()
property is a function.
Declaration files
Declaration files == Type definition files
TypeScript allows you to have Declaration Files which are files that allow you to describe the shape of code that’s written in (for example) plain JavaScript. So, by referencing one of these files you tell TypeScript exactly how that JavaScript code or library you are using should be assumed to be “typed”.
See: https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html
DefinitelyTyped
The repository for high quality TypeScript type definitions.
We can use DefinitelyTyped: lid.d.ts
and lib will be available to our app as if that lib were written in TypeScript
In Visual Studio, drag and drop lib.d.ts
, <reference path="lib.d.ts">
will be added