I'm trying to count the number of trees on $[n]$ given that $d_1,d_2,\dots,d_n$ are positive integers with $\sum_{i=1}^{n}d_i=2n-2$ and for $i\in[n]$ $\deg(i)=d_i$.
My thought process here is that since the sum of degrees is $2n-2$, we have $n-1$ edges. So the problem becomes counting the number of trees on $[n]$ with the condition that the graph has $n-1$ edges. In other words, just count the number of spanning trees on $[n]$. By Cayley's formula, I know that the number of spanning trees on $[n]$ is $n^{n-2}$.
A similar question has been asked on here before, so I'm sorry if this isn't how I'm supposed to ask my question, but an answer that looked different was given and I would really like to know why my logic here could be wrong.
link to the other question with a different answer: Number of trees with vertex set $[n]$ and vertex $i$ with $deg(v_i)=d_i$ s.t. $\sum d_i = 2n-2$
Your reasoning is not correct. Cayley's formula counts the total number of trees with $n$ labeled vertices without any restriction on the degree sequence of each tree. For this particular problem, we can use Prufer codes to find the answer, much like in the proof of Cayley's formula.
Recall that we construct the Prufer code for a labeled tree (with labels on $[n]$) with the following algorithm: at step $i$ we remove the leaf with the smallest label and set the $i$-th element of our code to be equal to the label of this leaf's neighbor. The algorithm terminates when only 2 vertices remain (i.e. after $n-2$ steps). It can be shown that this procedure produces a bijection between labeled trees on $[n]$ and the set of sequences on $[n]$ with length $n-2$. Moreover, given a Prufer code $\mathcal{C}$ corresponding to a (unique) tree $T$ the degree of the vertex labeled $i$ in $T$ is equal to the number of times $i$ appears in $\mathcal{C}$ plus one. So, our graph theory problem can be reduced to a counting one, namely, we want to count the number of sequences with length $n-2$ such that $d_i-1$ of the elements are equal to $i$ for all $i=1,2,\dots,n$. This number is equal to the multinomial coefficient: $$\binom{n-2}{d_1-1,d_2-1,\dots,d_n-1} = \frac{(n-2)!}{\prod_{i=1}^n (d_i-1)!}$$