EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials TypeScript Tutorial TypeScript Interface Default Value
Secondary Sidebar
TypeScript Tutorial
  • TypeScript Basic and Advanced
    • What is TypeScript?
    • Typescript Examples
    • TypeScript Versions
    • TypeScript Operators
    • JavaScript dump object
    • JavaScript get Method
    • Webpack ReactJS
    • Code Generator JavaScript
    • JavaScript Projects
    • Call Stack JavaScript
    • JavaScript Projects GitHub
    • JavaScript Filter Function
    • JavaScript nan
    • JavaScripttimestamp
    • TypeScript loop
    • CoffeeScript
    • TypeScript Webpack
    • setTimeout TypeScript
    • DHTMLX
    • CoffeeScript for loop
    • TypeScript number
    • JavaScript export module
    • TypeScript string contains
    • TypeScript Inheritance
    • TypeScript get
    • TypeScript undefined
    • TypeScript Global Variable
    • TypeScript Dictionary
    • TypeScript Generic
    • TypeScript Cast Object
    • TypeScript Optional Parameters
    • TypeScript? switch
    • TypeScript promise
    • TypeScript tuple
    • TypeScript Hashmap
    • TypeScript let
    • TypeScript Getter
    • TypeScript Pattern Matching
    • TypeScript number to string
    • TypeScript substring
    • TypeScript?lambda
    • TypeScript UUID
    • TypeScript JSDoc
    • TypeScript Decorators
    • Typescript for loop
    • TypeScript HTTP Request
    • TypeScript Abstract Class
    • TypeScript Question Mark
    • TypeScript Nullable
    • TypeScript reduce
    • TypeScript Mixins
    • TypeScript keyof
    • TypeScript string to number
    • TypeScript JSON parse
    • TypeScript const
    • TypeScript declare module
    • TypeScript String
    • TypeScript filter
    • TypeScript Multiple Constructors
    • TypeScript? Set
    • TypeScript string interpolation
    • TypeScript instanceof
    • TypeScript JSON
    • TypeScript Arrow Function
    • TypeScript generator
    • TypeScript namespace
    • TypeScript default parameter
    • TypeScript cast
    • TypeScript babel
    • Typescript Key-Value Pair
    • TypeScript if
    • TypeScript keyof Enum
    • TypeScript wait
    • TypeScript Optional Chaining
    • TypeScript JSX
    • TypeScript Version Check
    • TypeScript Unit Testing
    • TypeScript Handbook
    • TypeScript module
    • TypeScript Extend Interface
    • TypeScript npm
    • TypeScript pick
    • TypeScript Interface Default Value
    • JavaScript import module
    • Obfuscate Javascript
    • TypeScript basics
    • setInterval TypeScript
  • Type of Union
    • TypeScript Object Type
    • TypeScript type check
    • TypeScript promise type
    • TypeScript JSON type
    • TypeScript Union Types
    • TypeScript typeof
    • TypeScript Types
  • TypeScript Array
    • TypeScript Array of Objects
    • Methods TypeScript Array
    • TypeScript remove item from array
    • TypeScript add to array
    • TypeScript Array Contains
  • Function Of Array
    • TypeScript Function Interface
    • TypeScript Functions
    • TypeScript Export Function
    • TypeScript function return type

TypeScript Interface Default Value

TypeScript Interface Default Value

Introduction to TypeScript Interface Default Value

Entities have to confirm to a syntactical contract called interface. Here, a syntax gets defined by the interface which every entity has to follow. Methods, properties and events are defined by the interface and also are the members of the interface. Only the members are declared in the interface. The deriving class is responsible for defining the members. An interface even provides a standard structure to the deriving class which it has to follow. In this article, Typescript interface default value has been explained with its working and different examples. The examples would help the readers in the implementation of Typescript interface default value.

Interface Default Value in TypeScript Syntax:

To declare an interface, an interface keyword is used. Below syntax shows how to declare an interface in TypeScript−

interface interface_name {
…………
}

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Now within this declaration syntax of interface different objects can be defined whose default values are mentioned for example as,

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,818 ratings)

interface EDUCBA {
courseName:string,
courseDuration:number,
courseCode:number,
loginAccess: number,
supplementaryCourse: string,
greetings: ()=>string
}
Moving further these default values are given data as,
var course1:EDUCBA = {
courseName:"Data Science",
courseDuration:22,
courseCode: 22435,
supplementaryCourse: "Data Analyst",
loginAccess: 10,
greetings: ():string =>{return "Heyoo! We have Updated your Learning Course"}
}
In last it is called as,
console.log("Earlier Course ")
console.log(course1.courseName)
console.log(course1.courseDuration, "Hours")
console.log(course1.courseCode)
console.log(course1.supplementaryCourse)
console.log(course1.loginAccess, "Weeks")
console.log(course1.greetings())

Examples

Working with Interface Default Value in TypeScript explained with Examples:

Example #1

Code:

interface EDUCBA {
courseName:string,
courseDuration:number,
courseCode:number,
loginAccess: number,
supplementaryCourse: string,
greetings: ()=>string
}
var course1:EDUCBA = {
courseName:"Data Science",
courseDuration:22,
courseCode: 22435,
supplementaryCourse: "Data Analyst",
loginAccess: 10,
greetings: ():string =>{return "Heyoo! We have Updated your Learning Course"}
}
console.log("Earlier Course ")
console.log(course1.courseName)
console.log(course1.courseDuration, "Hours")
console.log(course1.courseCode)
console.log(course1.supplementaryCourse)
console.log(course1.loginAccess, "Weeks")
console.log(course1.greetings())
var course2:EDUCBA = {
courseName:"Finance",
courseDuration:24,
courseCode: 346678,
supplementaryCourse: "Business Analyst",
loginAccess: 10,
greetings: ():string =>{return "Heyoo!! Welcome"}
}
console.log("Updated Course ")
console.log(course2.courseName);
console.log(course2.courseDuration, "Hours");
console.log(course2.courseCode);
console.log(course2.supplementaryCourse);
console.log(course2.loginAccess, "Weeks")

Output:

typescript 1

Example #2

Code:

interface EDUCBA
{
(pricePaid: number,
courseName: string,
allotedTo: string,
loginID: number,
): void;
};
function newData
(
pricePaid:number,
courseName:string,
allotedTo: string,
loginID: number,
):void {
console.log(" Price Paid by You: INR = " + pricePaid)
console.log(" You choosed = " + courseName)
console.log(" Alloted to = " + allotedTo)
console.log(" Credentials to Login = " + loginID)
}
function updatedData
(
pricePaid: number,
courseName:string,
allotedTo: string,
loginID: number,
):void {
console.log(" Price Paid by You: INR = "+ pricePaid)
console.log(" You choosed = " + courseName)
console.log(" Alloted to = " + allotedTo)
console.log(" Credentials to Login = " + loginID)
}
let hi: EDUCBA = newData;
hi(19999,
'Data Science',
"Rahul Sharma",
345623);
hi = updatedData;
hi(26500,
'Finance',
"Rohit Khattar",
556879032);

Output:

typescript 2

Example #3

Code:

interface MobilePhone {
modelName: string;
modelNumber: number;
operatingSystem: string;
company: string;
price: number;
discount: number;
preBooking: string;
}
let Information = (type: MobilePhone): void => {
console.log(
'MobilePhone ' + type.modelName + ' of ' + type.company + ' has ' + type.operatingSystem + ' Operating System.'
);
};
let Information1 = (type: MobilePhone): void => {
console.log(
'MobilePhone ' + type.modelName + ' is quoted at ' + type.price + ' INR ' + ' . Discount of ' + type.discount + ' % can be availed on pre-booking' + ". Pre-booking starts on: " + type.preBooking
);
};
let Info = {
modelName: 'SM-4356',
modelNumber: 7823095467,
operatingSystem: 'Andriod',
company: 'Samsung',
price: 75000,
discount: 20,
preBooking: '20-March-2021'}
Information(Info),
Information1(Info);

Output:

TypeScript Interface Default Value

Conclusion

On the basis of the above article, we understood the concept of typescript interface and the default value of the interface. This article explains the concept with different examples and working. The examples would help the beginners in understanding the concept and implementing it according to their requirements.

Recommended Articles

This is a guide to TypeScript Interface Default Value. Here we discuss the introduction, syntax, Working with Interface Default Value in TypeScript with Examples respectively. You may also have a look at the following articles to learn more –

  1. TypeScript Multiple Constructors
  2. TypeScript typeof
  3. TypeScript Cast Object
  4. Typescript for loop
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more