Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

typescript interface vs type

// An interface can only describe objects, while a type is more flexible
type StringOrNumber = string | number; // not possible with interface

// An interface can be extended, while a type cannot. This makes
// interfaces great for generic components since a more specific
// component can extend its interface.
interface Dog extends Animal {
  tailShape: string;
  owner: string;
}
 
PREVIOUS NEXT
Tagged: #typescript #interface #type
ADD COMMENT
Topic
Name
6+4 =