First, preheat your oven to 400°F (about 200 °C). Generously butter or grease the baking dish so nothing sticks. Meanwhile, get your potatoes sliced uniformly—about an eighth of an inch thick—as even slices ensure consistent cooking.
In your sauté pan over medium heat, melt butter and then cook onion until translucent, about 4–5 minutes. Add garlic for another minute. Stir in flour and cook for one more minute to form a roux. Then whisk in warm stock and milk, add salt, pepper, and half the thyme. Let it gently simmer (don’t let it boil) until thickened.
Place half of your potato slices in an even bottom layer. Pour over half of the cream sauce (you can strain onion bits out first if preferred). Sprinkle one cup of cheddar and all the Parmesan. Then layer the rest of the potatoes, the remainder of sauce, and the other cup of cheddar.
Cover the pan loosely with aluminum foil and bake for 30–35 minutes or until bubbling around the edges. Remove the foil and bake uncovered for an additional 25–30 minutes until the cheese is golden and potatoes are fully cooked (use a fork to test). If the top browns too quickly, loosely cover it again.
Move the pan onto a wire rack and let it rest for about 10 minutes. Sprinkle with the remaining thyme and extra Parmesan, slice, and serve while warm.