This one will convernt TS to JS: tsc fileName.ts
If we want to monitor TS change Realtime then: tsc fileName.ts --watch
String =: let firstName: string = "Zulkar Nayin";
Number =: let studetnId: number = 2314;
Boolean =: let isActive: boolean = true;
Any =: let bjit: any = "Software Company";
Array: let studentList: any[] = ["zulkar", 463];
Unit Type =: let studentList: (string | number)[] = ["zulkar", 463];
let arr: [string, number] =["zulkar Nayin", 16303045] \
Reference: https://www.typescriptlang.org/docs/handbook/enums.html#handbook-content
Type:
string
numeric
Heterogeneous
example: enum RollType {STUDENT, ADMIN, TEACHER}
let WhichROll: RollType
let students: object; \
let student: {name: string, id:number}; \
let student: {name: string, id?:number}; //? sign for keep optional \
let student: object[]; //For store arry of object
type RoolType = "Admin" | "user";
let UserRoll: RoolType;
UserRoll = "Admin";
class Student{
name: string;
age: number;
constructor(userName:string, age:number) {
this.name = userName;
this.age = age;
}
studentDetails() {
console.log(`student name is ${this.name}, and age is ${this.age}`);
}
};
let studentOne = new Student("Zulkar Nayin", 16303045);
studentOne.studentDetails();
class university extends Student {
department: string;
constructor( name:string, age:number ,studentDepartment:string) {
super(name, age);
this.department = studentDepartment;
}
}
let signleData = new university("Zulkar", 25,"CSE");
public name: string; //All the public members can be accessed anywhere without any restrictions.
private accountNo: number; //The private access modifier ensures that class members are visible only
to that class and are not accessible outside the containing class.
protected DBPASSWORD: any; //protected members can be accessed using their deriving classes only.
Abstraction is a process of hiding the implementation details and showing only functionality to the user.
class declared with abstract keyword
object can not be created from abstract class
if a class extends abstract class; it must inherit all the abstract methods \
function identity<Type>(arg: Type): Type {
return arg;
}