Whisk 1 cup (200 g) granulated sugar, ¾ cup (63 g) unsweetened cocoa powder, 2 Tbsp. instant espresso powder or unsweetened cocoa powder, 2 Tbsp. cornstarch or potato starch, and ¼ tsp. kosher salt in a medium saucepan. Add 1 cup whole milk, whisking until a smooth paste forms, then whisk in remaining 2½ cups milk. Place saucepan over medium heat; bring to a simmer. Cook, whisking often, until very hot to the touch. Switch to a heatproof rubber spatula; continue to cook, stirring constantly and scraping down sides of pan, until thickened, 3–4 minutes more. Remove from heat and whisk in 1 tsp. vanilla extract. Let cool 10 minutes, whisking occasionally to prevent a skin from forming.