TypeScript Hindi Tutorial #27 Modules

Module in TypeScript

What is modules in TS?

Example.

Interview Questions.


What is Module ?

Self-contained unit of code that encapsulates related functionalities, such as classes, functions, and variables


main.ts

import { Auth } from "./inheritance";
import UserInfoType from "./type/type";

var userInfo:UserInfoType={
name:'anil',
age:30,
email:'anil@test.com',
password:'1234@abc'
}

class User extends Auth{
}

var user1 = new User();

user1.login(userInfo.name,userInfo.password)
console.log(userInfo);


type.ts

export default interface UserInfoType {
name:string,
age:number,
email:string,
password:string,
}


Inheritance.ts

export class Auth{
login(name: string, password: string) {
if (name && password) {
return "Student Login"
} else {
return "not Login"
}
}
}

class Student extends Auth{
result(marks:number){
if(marks>33){
return "Pass"
} else{
return "failed"
}
}
}

var s1= new Student();
console.log(s1.result(60));


class Teacher extends Auth {

subject(subject:number){
return "he tech"+subject
}
}

var t1 = new Teacher();
console.log(t1.login("sam","12345"));