2ality | JavaScript and more
Follow
TypeScript: checking Map keys and Array indices
JavaScript has two common patterns:Maps: We check the existence of a key via .has() before retrieving the associated value via .get().
Arrays: We check the length of an Array before performing an indexed access.These patterns don’t work as well in TypeScript. This blog post explains why and presents alternatives.