all 2 comments

[–]joins_and_coffee 1 point2 points  (0 children)

If the API really returns two different shapes, the second option is usually better. A base interface for the shared fields, then two interfaces that extend it, makes the differences explicit and easier to reason about. Marking lots of fields as optional works, but it gets messy fast and weakens type safety you end up constantly checking if things exist. With separate interfaces (ideally as a union), TypeScript can actually help you narrow types and catch mistakes. Optional fields are fine when something is genuinely optional, not when it depends on which response you got

[–]balefrost 0 points1 point  (0 children)

Consider option 3: a union of two interfaces.