Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # `ItemType` Generic Utility Type
- This is to describe the situation where one might want to use the type of an array indirectly.
- The ItemType generic is sugar over an existing capability in TypeScript to access the type information of the Array generic
- 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",
- and to their point, I agree... mostly.
- It's almost always better to declare a variable to be of the Array's type directly.
- But I'm finding there are situations where I linking a local variable's type to an interfaces's member type to be
- more maintainable because it helps the compiler direct me to type errors as I refactor code more effectively.
- 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