Effective TypeScript › Writing a safe querySelector: the one-way street from values to types
The DOM's document.querySelector method is ubiquitious in JavaScript but somewhat tricky to type in a safe way. This post walks through how you can create a safe querySelector for use in TypeScript code and explains how this is an example of a general pattern of using values (which exist at runtime) as a source of truth, rather than types (which don't).