It seems to me that any proof of
If $I\subseteq \mathbb{R}$ is an interval and $h:I\to\mathbb{Q}$ is continuous, then it is constant $\hspace{4mm}$ ($\ast$)
or variants thereof that invokes the Intermediate Value Theorem (IVT) is incorrect because (as far as I'm aware) the proofs I've seen of the IVT relies on the fact that the image of $f$ must be connected. However if the codomain of $f$ is already restricted to $\mathbb{Q}$ (or if we stipulate the image of $f$ to only rational values) then we cannot apply the IVT. Is it just me or am I missing something here?
The highest voted answers for these questions below uses the IVT where the first question has been an accepted as an answer.
Prove that if $f: \mathbb{R} \to \mathbb{Q}$ is continuous then $f$ is constant
Is a rational-valued continuous function $f\colon[0,1]\to\mathbb{R}$ constant?
Addendum:
Statement of the IVT that I am using:
Let $I$ be an interval and suppose $f:I\to\mathbb{R}$ is continuous. If $a,b\in I$ and $y\in\mathbb{R}$ satisfies $f(a)<y<f(b)$ then there is a $c\in (a,b)$ such that $f(c)=y$
I have resolved my confusion and it comes down to the assumption of $f$ having codomain $\mathbb{R}$ in the statement of the IVT. I was thinking that if we had a function, say the one in ($\ast$) where the codomain is $\mathbb{Q}$ then we cannot apply the IVT because it does not meet the assumptions of the theorem, so then I had to look at the proof of the theorem to see if the codomain really had to be $\mathbb{R}$. In all the proofs I have seen (and I'm sure that almost every proof of the IVT would have this step) there is this step where we suppose that
" $y\in \mathbb{R}$ such that $f(a) < y < f(b)$ "
that caused me to conclude that the codomain had to be $\mathbb{R}$ in order for the IVT to work because $y$ can be irrational, and if $f:I\to\mathbb{Q}$ then how can we conclude that there is a $c\in (a,b)$ such that $f(c)=y$ because $f$ can only take rational values? That erroneously caused me to conclude that the assumption that the function has codomain $\mathbb{R}$ had to be the case. However, this is exactly the flaw in my thinking because as stated in the comments, the codomain does not exactly have to be $\mathbb{R}$ but as long as it is a subset of $\mathbb{R}$. Thus, the IVT should really be of the form
Let $I$ be an interval and $S\subseteq \mathbb{R}$. Suppose $f:I\to S$ is continuous. If $a,b\in I$ and $y\in\mathbb{R}$ satisfies $f(a)<y<f(b)$ then there is a $c\in (a,b)$ such that $f(c)=y$.
Hence, $S$ is just some arbitrary subset of $\mathbb{R}$ and in proving the theorem we conclude that $S$ had to in fact be an interval. That's why I had my qualm as to why we can use the IVT to prove ($\ast$) since $h$ does not meet the assumptions of the theorem since the codomain of $h$ is $\mathbb{Q}$.
Now some may ask, but since $\mathbb{Q} \subseteq \mathbb{R}$ then surely the IVT can still be applied to any function who's codomain is a subset of $\mathbb{R}$. I'm not sure if in general we can do this even though in the case of the IVT it happens to be fine?
Bear in mind that the converse is not implied here (that is, we do not assume $f(I)$ is an interval), so you've got things backwards or the proofs you've seen have been somewhat missing the point.
– PrincessEev Apr 21 '21 at 03:34