Preheat your oven to 350°F (175°C). Grease a shallow 2-quart baking dish or a 9-inch square pan to prevent sticking.
Boil or steam the peeled and cubed sweet potatoes until they are very tender, about 12–15 minutes. Drain well and return to the pot.
Mash the potatoes smoothly, then stir in melted butter, brown sugar, heavy cream or milk, vanilla, cinnamon, nutmeg, and 1/2 teaspoon salt. Mix until everything is well combined and creamy.
Spread the creamy potato mixture in the prepared dish, smoothing the top with a spatula.
Make the pecan topping: in a small bowl, combine chopped pecans, 2 tablespoons melted butter, 2 tablespoons brown sugar, and a pinch of salt. Stir until the mixture clumps slightly.
Scatter the pecan topping evenly over the potato mixture.
Bake for 25–30 minutes, until the top is bubbling and the edges are lightly golden. If you like a crisper topping, you can broil for 1–2 minutes at the end, watching closely to prevent burning.
Let the casserole rest for about 5 minutes before serving. This makes it easier to cut and helps the flavors settle.