An interface in TypeScript is similar to other object oriented programming languages interfaces. An interface is a way to define a contract on a function with respect to the arguments. Stayed Informed – Learn Angular 2 In the below example, I am using an interface that describes objects that have a “name”, “age” and “address” fields and the following code defines an interface and a function that takes a parameter that adheres to that interface. //USER INTERFACE interface User { name: string ; age: number ; address: string } //FUNCTION USING USER INTERFACE let userInfo = function (user: User ) { let info = "Hello, " + user.name + " Your Age is - " + user.age + " and Address is -" + user.address; return info; } //USER INFO JSON OBJECT let info = { name : "Anil" , age: 30 , address : "Noida, India." }; //RESULT console.log(userInfo(info)); I hope you ...
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers