Preheat the oven to 375°F (190°C). Peel and slice the sweet potatoes into 1/8 inch thick slices. Place them in a large bowl.
In the same bowl, add cranberries, heavy cream, brown sugar, cinnamon, nutmeg, salt, and black pepper. Mix gently to coat the sweet potatoes and cranberries.
Layer half of the sweet potato mixture in a greased baking dish. Sprinkle half of the cheddar and Parmesan cheese on top. Add the remaining sweet potato mixture and finish with the rest of the cheese. If using, sprinkle pecans on top.
Cover the dish with aluminum foil and bake for 30 minutes. Remove the foil and bake for an additional 20-25 minutes until golden and bubbly. Let cool for 10 minutes before serving.