TypeScript is a superset of JavaScript. When TypeScript is compiled, it transpiled to JavaScript.
Features:
- Static Typing
- Interfaces
- Class Properties
- Access modifiers (Public, Private)
Static Typing:
let name: string
let age: number
let dob: data
Interfaces:
interface IEmp {
name: string
age?: number //Optional property
dob: date
}let myEmp: IEmp
Class Properties:
class Employee {
name: string}
dob: date
constructor (name){
this.name = name
}
Access Modifier:
Class members are public by default in both ES6 and TypeScript.
class Employee {
private name: string}
private getSalary() {
console.log(‘Salary of ’ + this.name + ‘ is $5000.00‘)
}
let myEmp = new Employee ()
console.log(myEmp.name) //Compile time error
Thanks,
Bimal
No comments:
Post a Comment