One of the greatest additions to the javascrcipt ecosystem has been the addition of typescript
. one important part that was introduced in typescript
was the ability to define interface
. simply put an interface is a way to define a structural contract to the consumer of a particular
code or more generally interface is a group of related properties and methods that describe an object
.
One thing to remember is that interfaces are just used by the transpiler to do type checking.nothing more nothing less! once transpiled to javascript there is no meaning of interfaces as javascript is not a typed language.
Now to create an object that confirms with the defination of Point inteface , we can write.
Now assume there is a consumer of this Point object which always expects the object passed to it always has a x
& y
property defined.
If we now by mistake make a call to draw
method like this