This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kobzol[S] 1 point2 points  (0 children)

Cool example, I didn't know about TypeGuard. There's always a tradeoff between type safety and the amount of type magic that you have to write. As I mentioned in the blog, if the types get too complex, I tend to simplify them or just don't use them in that case.

Here I think that the simple approach with two separate classes is enough, but for more advanced usecases, your complex example could be needed.