Guest User

Untitled

a guest
Nov 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # `ItemType` Generic Utility Type
  2.  
  3. This is to describe the situation where one might want to use the type of an array indirectly.
  4.  
  5. The ItemType generic is sugar over an existing capability in TypeScript to access the type information of the Array generic
  6. and make accessing that type more legible to the reader. But a few people replied with "huh, I don't think you want to do that",
  7. and to their point, I agree... mostly.
  8.  
  9. It's almost always better to declare a variable to be of the Array's type directly.
  10.  
  11. But I'm finding there are situations where I linking a local variable's type to an interfaces's member type to be
  12. more maintainable because it helps the compiler direct me to type errors as I refactor code more effectively.
  13.  
  14. So here's a concrete use case that is simplified situation where I would use this pattern and I'll explain why afterwards.
Add Comment
Please, Sign In to add comment