Difference between extending and intersecting interfaces in TypeScript?
问题 Let's say the following type is defined: interface Shape { color: string; } Now, consider the following ways to add additional properties to this type: Extension interface Square extends Shape { sideLength: number; } Intersection type Square = Shape & { sideLength: number; } What is the difference between both approaches? And, for sake of completeness and out of curiosity, are there other ways to yield comparable results? 回答1: Yes there are differences which may or may not be relevant in your