Preheat the oven to 180C/350F and line a 12 hole cupcake pan with liners.
Place the butter and sugar into a large bowl or the bowl of your stand mixer and beat until light and fluffy, 2-3 minutes on medium high speed.
Add in the eggs and coconut extract, scraping down the sides as necessary, and mix on medium speed until well combined, around 1 minute.
Add in the flour, baking powder, salt and spices and mix on low until the mixture starts to come together, then add the pumpkin puree and mix on medium speed until well combined and smooth.
Add in the coconut flakes, if using, and fold in by hand.
Divide the batter between the cupcake liners, filling them 3/4 full. I use a 2tbsp cookie scoop to ensure even cupcakes.
Place in the oven for 18-22 minutes, until risen, golden and an inserted skewer into the centre comes out clean. Transfer to a wire rack to cool immediately. This helps prevent the liners peeling away from the sides.
If you're going to garnish the cupcakes with coconut flakes, lightly toast them while the cupcakes are cooling. I placed around 2tbsp of coconut flakes into a small, dry frying pan and placed them over a medium heat. They will turn golden with brown edges when ready - this will take 2-4 minutes.
Once completely cool, make the frosting: Place butter, sugar and coconut extract into a large bowl, or the bowl of your stand mixer, and mix on low until the sugar starts to combine with the butter.
At this point, turn up the speed to medium high and beat until combined. Add in coconut milk 1tbsp at a time, until you have a thick, creamy frosting which holds its shape, but is able to be piped.
Half fill a piping bag fitted with either an open star nozzle or a plain one and pipe a swirl onto each cupcake. Garnish with toasted coconut flakes.
Pumpkin Coconut Cupcakes will keep in an airtight container, at room temperature for 4 days.