In a small saucepan over medium heat, add the walnuts or pecans if using. Toast them for about 2–3 minutes, stirring frequently, until they become fragrant and slightly golden.
Once the nuts are toasted, add in the grated carrot, then add the granulated sugar, dark brown sugar, and water. Stir to combine.
Add the cinnamon sticks (or ground cinnamon), salt, nutmeg, and ginger. Stir well and bring the mixture to a gentle simmer over medium heat.
Allow the syrup to simmer gently for about 10 minutes, stirring occasionally, so the flavors from the toasted nuts and warm spices infuse into the syrup.
Remove the saucepan from the heat and strain the mixture through a fine mesh strainer to remove the carrot, nuts and cinnamon sticks.
Stir in the vanilla extract and the cream cheese extract, if using.
Let the syrup cool completely before transferring it to a glass jar or bottle. Store in the refrigerator for up to 3 weeks.