Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I really don't get the point of operations on types such as 'type TodoInfo = Omit<Todo, "completed" | "createdAt">'. Is this a real use case? Why not just literally write down the properties? Surely easier to read and in the end maybe even easier to maintain.


It depends on what your anticipation of the future evolution of TodoInfo type is.

If you think it will have more special fields like completed and createdAt that you don't want to pass on in most contexts, then it's better to list the fields that you want to pass on.

But if you expect it to not have more of those and rather get (or loose) more fields that you want to pass on, then it's better to list the ones that you want to omit.

Another trade-off might be that when the new field is added and you'll forget to update the other pieces of code, will it do less harm to pass the field you intended to omit, or to omit the field you intended to pass. Or which error will be easier for you to discover in your use case.


A higher order react component that consumes those props and swallows them before passing down to the target.


Renaming attributes propogates through these types. It makes refactoring better.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: