Prepare the pie shell by baking it according to package instructions or your favorite recipe. Allow it to cool completely before filling.
In a medium mixing bowl, whisk together sugar, flour, and salt until well blended.
Heat the milk in a saucepan over medium heat until steaming but not boiling.
Gradually whisk the warm milk into the dry mixture until smooth. Cook over medium heat, stirring constantly until thickened and gently boiling.
Beat the egg yolks in a small bowl. Slowly add a few tablespoons of the hot mixture into the yolks, whisking constantly to temper them.
Pour the tempered egg yolk mixture back into the saucepan with the remainder of the filling. Cook 2-3 more minutes, stirring until thickened. Remove from heat.
Stir in the flaked coconut, butter, vanilla extract, and cream cheese until smooth and well combined.
Pour the creamy coconut filling into the cooled pie shell, spreading evenly. Let cool at room temperature briefly before refrigerating.
Refrigerate the pie for at least 4 hours or until set. Optionally, top with whipped cream and additional flaked coconut before serving.