My discrete mathematics book says:
But I read an answer, https://math.stackexchange.com/a/2415543/390226, said:
["...]There are invertible functions which are not bijective,[..."]
And to the same question in the link, an answer said:
["]A function is invertible if and only if it is injective[."]
So for a function to have a inverse, it must be bijective. But any function that is injective is invertible, as long as such inverse defined on a subset of the codomain of original one, i.e. the image of the original function?


It all depends on the co-domain of your function.
When you have a function $$f:A\to B$$ which is one-to-one but not onto $B$, you may restrict your co-domain to a subset of $B'\subset B$ which is the range of $f$.
For example $$f:N \to N $$ defined by $$f(n)=2n$$ is not onto but it is one-to-one.
If we define, $$f^* : N\to 2N$$ with the same definition $f^*(n)=2n$
We have an inverse function, $(f^*)^{-1} (n) = n/2.$