Preheat the oven to gas 7, 220°C, fan 200°C. Put the duck legs into a large ovenproof frying pan or flameproof casserole, then roast for 30 minutes. While you wait, deseed and finely chop the chilli if using, cut the pineapple into chunks and deseed and thickly slice the pepper.
Lift the duck out of the pan and discard the excess fat, leaving about 1 tbsp behind. Turn the oven down to gas 3, 160°C, fan 140°C. Put the pan on the hob then add the sugar, curry paste and half of the chilli if using. Fry for 2 minutes, stir in the coconut milk plus a can of water, the fish sauce and lime leaves, then return the duck to the pan. Cover the pan leaving a small gap for some steam to escape, then return to the oven. After 1 hour, skim off the fat from the top, add the pineapple and peppers and return the pan to the oven, uncovered. Cook for another 30 minutes until the duck is tender and cooked through.
Skim the surface again, then season the sauce with the lime juice. The sauce should be sweet, sour, salty and hot, without one particular flavour being too dominant. If needed, add more fish sauce, sugar or chilli. Scatter over the basil leaves then serve with rice.
If you can't get hold of kaffir lime leaves, finely grate the zest of 1 lime and add it to the sauce at the end of cooking.
See more Thai recipes
For top tips on protecting you and your family when preparing raw meat and poultry, visit Food Safety in the Home and view the full Food safety at home video.