Typescript is an open-source language similar to javascript with more advanced features.
It provides type safety for JavaScript code during the compilation phase.
Typescript files created with the ts
extension, that compiled to javascript(.js extension)
Typescript = Superset of Javascript + Optional Type Safety Checking.
Why Typescript is preferred over Javascript
Typescript provides the following features
- Type Inference
- Type Annotations
- Type Alias
Typescript features
- Typescript Primitive Types Any data in typescript is typed at compiled time. The following are types.
Type | Description |
---|---|
any | any type accepts any value, equals to javascript variable declaration |
unknown | data type is not known at |
boolean | boolean contains true or false values |
number | numbers contains values of positive, negative, and float values |
bigint | BigInteger to represents larger integers to avoid rounding errors |
string | Represents Group of characters |
symbol | used to define keys in objects and maps |
Objects | Objects are basic entities created using typed aliases, interface, and classes |
Arrays | Datastructures to represent a sequence of objects of the same type |
Enum | Enumeration of fixed key and values |
Type aliases | used to declare typed aliases for custom types |
Unions | Represents union of types |
Tuple | Represents an array of multiple types |
never | Type that never returns any value from a function |
void | Type represents functions that do not return any value |
Feature | Description |
---|---|
Primitive Types | Typescript Inbuilt Primitive Types |
Compiler | Typescript compiler, convert to Javascript |
Handle Errors | Error handling using try, catch, throw. |
horizontalPosition | Horizontal position - ‘start’, ‘center’, ’end’, ’left’, ‘right’ |
Classes | Object Oriented Classes |
Polymorphism | functions overloading and overriding |
Encapsulation | Setter and getter to provide abstraction and protection data |
Interface & Abstract | Define interface and abstract classes |
Modules | Import and export modules |
Latest Typescript Version
The current Latest version is 4.8.3.
Reference: