Preheat your oven to 350°F (175°C) if you are baking a pie crust from scratch.
In a medium saucepan, combine the granulated sugar, cornstarch, and salt. Gradually whisk in the coconut milk until smooth.
Over medium heat, cook, stirring constantly, until the mixture thickens and begins to bubble (about 10-15 minutes).
In a separate bowl, whisk the egg yolks. Slowly temper the egg yolks by adding a small amount of the hot coconut mixture to them while whisking continuously to prevent scrambling.
Once tempered, add the egg yolk mixture back to the saucepan, and continue to cook for another 2-3 minutes, stirring constantly until thickened.
Remove from heat and stir in the butter, vanilla extract, and coconut extract (if using). Fold in the shredded coconut.
Pour the filling into the pre-baked pie crust, spreading it evenly. Allow it to cool to room temperature, then refrigerate for at least 4 hours until set.
Before serving, whip the heavy cream and powdered sugar until stiff peaks form. Spread or pipe the whipped cream over the chilled pie.
Sprinkle the toasted coconut on top of the whipped cream as a finishing touch.