javascript - In Typescript, what is the difference between type and interface? -
what differences between following?
type foo = { foo: string }; interface foo { foo: string; }
interfaces can extended
interface { x: number; } interface b extends { y: string; }
and augmented
interface c { m: boolean; } // ... later ... interface c { n: number; }
type aliases, however, can represent things interfaces can't
type numorstr = number | string; type neatandcool = neat & cool; type justsomeothername = sometype;
so in general if have plain object type, shown in question, interface better approach. if find wanting write can't written interface, or want give different name, type alias better.
Comments
Post a Comment