3 ms·
I appreciate the effort you’ve both put in to concrete examples. I think yours gets to a point that I haven’t often seen stated. You’ve named your interface Per
by dmohs 6y ago
I appreciate the effort you’ve both put in to concrete examples. I think yours gets to a point that I haven’t often seen stated. You’ve named your interface Person, but perhaps even Emailable could serve the purpose. The problem is that you had to name it. Naming well is hard, and I believe strong type systems often create a need for more names. It’s a cost I don’t often see considered in the tradeoff.
- dmux 6y agoInstead of giving the interface an explicit name, I think you could instead use something like this: function getEmails(group: Array<{email: string}>) { return group.map((p) => p.email) } which leaves the function more open ended than relying on an explicitly named interface that other types then have to inherit from.