Final answer:
In TypeScript, use interfaces to define contracts or shapes of objects and when you need declaration merging, and use types for unions, intersections, tuple types, and mapped types, prioritizing flexibility.
Step-by-step explanation:
The decision of when to use type versus interface in TypeScript depends on the particular needs of your code. Interfaces are generally preferred for defining contracts within your code, particularly when it comes to the shapes of objects or when you need to define a contract for a class to implement. Interfaces also support declaration merging, which allows you to split the definition across multiple declarations, which is helpful in extending third-party type definitions.
Using types, on the other hand, is beneficial when you need to use unions or intersections, define tuple types, or when you want to map types. Types are more flexible but do not support declaration merging like interfaces do. Thus, your choice might boil down to the need for flexibility (types) versus the need for declaration merging and implementing contracts (interfaces).
Ultimately, the choice between type and interface commonly arises in more advanced TypeScript usage scenarios. It's important to consider the specific features each construct provides and how they align with the requirements of your codebase.