TypeScript Hindi Tutorial #19 Interface

Interface

An interface is a way to define the structure of an object, function etc.


What is Interface.

Define Interface

How to use Interface

Extend Interface


Interface.ts

interface Info {
name:string,
age:number,
college:string
}

interface TeacherType extends Info {
subject:string
}

var studentObj:Info ={
name:'anil',
age:30,
college:'IET alwar'
}
var teacherObj:TeacherType={
name:'Sam',
age:40,
college:'IET alwar',
subject:'Math'
}

var management:Info={
name:'Sam',
age:40,
college:'IET alwar'
}


Interface.js

"use strict";
var studentObj = {
name: 'anil',
age: 30,
college: 'IET alwar'
};
var teacherObj = {
name: 'Sam',
age: 40,
college: 'IET alwar',
subject: 'Math'
};
var management = {
name: 'Sam',
age: 40,
college: 'IET alwar'
};