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

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -