Interface and class in TypeScript
<p>In C# there's a quite huge difference between interfaces and classes. Indeed, a class represents a reference-type, so that we can actually create objects modeled on that class, while interfaces are meant to be contracts that a class sign to in order to ensure the existence of a certain behavior. In particular we can't create instances of interfaces.</p>

<p>The whole point with interfaces is to expose behavior. A class implements it by giving one explicit implementation of said behavior.</p>

<p>In that case, although interfaces <em>may</em> contain properties, most of the time we care about interfaces because of behavioral issues. So most of the type, interfaces are just contracts of behavior.</p>

<p>On TypeScript, on the other hand, I've seem something that made me quite uneasy, and in truth I've seen this more than once, which is the reason for this question.</p>

<p>In one tutorial I saw this:</p>

<pre><code>export interface User {
    name: string; // required with minimum 5 chracters
    address?: {
        street?: string; // required
        postcode?: string;
    }
}
</code></pre>

<p>But wait a minute. Why <code>User</code> is an interface? If we think like C#, <code>User</code> shouldn't be an interface. In truth, looking at it, it seems like we are defining the data type <code>User</code>, instead of a contract of behavior.</p>

<p>Thinking like we do in C#, the natural thing would be this:</p>

<pre><code>export class User {
    public name: string;
    public address: Address;
}
export class Address {
    public street: string;
    public postcode: string;
}
</code></pre>

<p>But this thing of using interfaces like we do with classes, to just define a data type, rather than defining a contract of behavior, seems <em>very common</em> in TypeScript.</p>

<p>So what interfaces are meant for in TypeScript? Why do people use interfaces in TypeScript like we use clases in C#? How interfaces should be properly used in TypeScript: to establish contracts of behavior, or to define properties and object should have?</p>