Why we use TypeScript!
TypeScript is a programming language developed and maintained by Microsoft. It introduces additional features like strict type binding (variables are bound to specific data types) to JavaScript and can also be compiled down to JavaScript as well.
If we want a large-scale project that time TypeScript is helping us to reduce code error.
And
Secondly, TypeScript means the defined type before declaring.
*Without defining Type *
function addTwo(num)
{
return num + 2;
}
addTwo(2); // Returns 4;
addTwo("Two"); // Returns "Two2"
** Typing**
function addTwo(num : number)
{
return num + 2;
}
addTwo(2); // Returns 4;
addTwo("Two"); // Compile Error
Implementation of Interface in ts file
interface Vehicle{
wheels: Number;
}
class Car implements Vehicle {
public wheels: Number;
public hasTrunk: Boolean;
}
class MotorCycle implements Vehicle{
public wheels : Number;
}
TypeScript Explained Further
TypeScript has two different roles depending on its configuration and usage.
- TypeScript as a linting layer on top of JavaScript TypeScript supports a more robust interaction with the editor by adding additional syntaxes to JavaScript with type checking and code completion. Also, it helps catch errors easier in the early development phase.
- TypeScript as a Transpiler Transpiler is a tool that converts a code written in one programming language into another language with a more similar abstraction level. TypeScript has its own transpiler, which can convert .ts files into .js, making it possible for browsers to execute your code.
Top comments (0)