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.

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.