If using a store-bought crust, bake according to package directions and cool completely on a wire rack. If making your own crust, blind bake at 375°F (190°C) for 15-18 minutes until golden brown, then cool completely.
In a medium saucepan, whisk together the granulated sugar, cocoa powder, cornstarch, and salt until no lumps remain.
Pour about 1/2 cup of the whole milk into the dry ingredients and whisk until you have a smooth paste. Gradually whisk in the remaining milk until completely smooth.
Place the saucepan over medium heat and cook, whisking constantly, for 8-10 minutes until the mixture thickens and starts to bubble. The custard should coat the back of a spoon when ready.
In a small bowl, whisk the egg yolks until smooth. Slowly drizzle about 1 cup of the hot custard mixture into the yolks while whisking constantly to temper them. Pour the egg mixture back into the saucepan while whisking.
Return the saucepan to medium heat and cook for 2-3 more minutes, whisking constantly, until the mixture thickens further and becomes glossy with a pudding-like consistency.
Stir in the chopped dark chocolate, butter, and vanilla extract until completely melted and incorporated. The filling should be smooth, glossy, and deeply chocolate-flavored.
Pour the filling through a fine-mesh strainer into a clean bowl to remove any lumps. Let it cool for about 10 minutes, stirring occasionally to prevent a skin from forming.
Pour the chocolate custard into your cooled pie crust and spread it evenly with a rubber spatula. Press a piece of plastic wrap directly onto the surface of the filling to prevent a skin from forming.
Refrigerate the pie for at least 4 hours or overnight until the filling is completely set. Don't skip this step—patience is key for perfect slices.
When ready to serve, pour the cold heavy cream into a chilled mixing bowl. Add the powdered sugar and vanilla extract. Beat with an electric mixer on medium-high speed until stiff peaks form, about 3-4 minutes. Don't overbeat.
Remove the plastic wrap from the chilled pie. Spread or pipe the whipped cream over the entire surface. Use a vegetable peeler to create chocolate shavings from a chocolate bar and sprinkle generously over the whipped cream.