• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Declaring Interface in TypeScript Angular 2

September 23, 2017 by ProjectsGeek Leave a Comment

Interface in TypeScript

Interface in TypeScript

In this post we will see how to declare Interface in TypeScript and the using this interface for passing objects to function.

In below code we have interface Point which have defining of holding two variables ‘x’ and ‘y’ with the data type number. Then we have one function doSomething() which is accepting point object of type Point interface.

interface Point {

    x: Number,
    y: Number
}

let doSomething = function(point: Point) {
    console.log('Point X: '+point.x);
    console.log('Point Y: '+point.y);
}


doSomething({x:1,y:2});

At the last line we have calling function doSomething()  with the object.

How to create object in Typescript ?

As in this case we have two variables inside class or interface of type number.

{
           x:1,
           y:2

}

Now run this code using node.

PS C:\Users\AnilKumar\ts-hello> tsc code-main.ts
PS C:\Users\AnilKumar\ts-hello> node code-main.js
Point X: 1
Point Y: 2
PS C:\Users\AnilKumar\ts-hello>

Other Projects to Try:

  1. Declaring Classes in TypeScript Angular 2
  2. Declaring Constructors in TypeScript Angular 2
  3. TestPage
  4. Public and Private Keywords
  5. Difference between VAR and LET Angular 2

Filed Under: Angular 2 Tagged With: Angular 2

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy