DEV Community

Discussion on: The Strictest TypeScript Config

 
bwca profile image
Volodymyr Yepishev

Just dropping my 2 cents, the possible undefined problem of the aforementioned record can be solved by an explicit cast in the value lookup, it's just that both the object and its key need to be casted.

let obj: Record<string, { func: Function }> = {}

for (let key of Object.keys(obj)) {
  (obj[key] as typeof obj[typeof key]).func(); // ✅
}
Enter fullscreen mode Exit fullscreen mode

Though the case seems rather artificial, as you'd probably be using .values or .entries :P

Thread Thread
 
what1s1ove profile image
Vladyslav Zubko • Edited

Hey @bwca !
Thank you for sharing your approach to solving the problem!
I believe it's challenging to assess it solely based on this small code snippet. In real projects, everything can be significantly different 🥲