Typescript interfaces

From wikinotes
Revision as of 03:28, 11 December 2022 by Will (talk | contribs) (Created page with "In typescript, interfaces are implicit -- any object that satisfies the requested interface is allowed.<br> Interfaces can be extended (grown) into new interfaces that include others. = Interface = <blockquote> <syntaxhighlight lang="typescript"> interface Person { firstName: string; lastName: string; } interface Employee extends Person { id: number; } </syntaxhighlight> </blockquote><!-- Interface --> = Type Alias = <blockquote> You can also define a type...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

In typescript, interfaces are implicit -- any object that satisfies the requested interface is allowed.
Interfaces can be extended (grown) into new interfaces that include others.

Interface

interface Person {
    firstName: string;
    lastName: string;
}

interface Employee extends Person {
    id: number;
}

Type Alias

You can also define a type-alias, but you cannot extend it in a new interface.

type Point {
    x: number;
    y: number;
}