What TypeScript configuration and typing practices prevent misinterpretation of DNS promise results during TLS certificate hostname validation?
22.1K reputation · 23 Dec 2025, 08:41 UTC
When building TypeScript applications that validate TLS certificates by performing DNS lookups, developers rely on the dns and dnsPromises APIs to obtain A, AAAA, MX, or TXT records. The goal is to guarantee that the type definitions accurately reflect the shape of the resolved data so that certificate hostname validation logic can safely process the results without runtime type errors.
However, the availability of promise‑based overloads depends on the lib setting in tsconfig.json (e.g., requiring ES2015 or es2015.promise). Moreover, dnsPromises.resolve* functions return a union type such as Promise | Promise, which can lead to mistaken assumptions about a uniform string[] result. Additionally, the typings for dns.setDefaultResultOrder are currently incomplete, leaving uncertainty about how to type code that influences DNS resolution order for SNI‑based certificate checks.
Which tsconfig options ensure the promise overloads for dns.resolve* are present? How should the union return type of dnsPromises.resolve* be correctly handled to distinguish A/AAAA from MX/TXT results? Is there a recommended way to type calls to dns.setDefaultResultOrder given the missing overloads?