Dimension Theorem Corollary Let $V$ and $W$ be vector spaces with $\dim V = \dim W$. If $T : V → W$ is
linear then $T$ is one-to-one if and only if $T$ is onto. 
But this is true only when the dimensions of $V$ and $W$ are finite.
For instance I came across the example $T : P(R)\to P(R)$ such that $T(f(x))=f'(x)$. Here T is onto but not one-one.
Can we generalize the case for infinite dimensions too in any way?
 A: Firstly, note that without the axiom of choice, we can't speak about the dimension of a vector space in general, because there would be vector spaces without a basis! For the rest of this post, I will be assuming the axiom of choice without comment.

Every vector space has a dimension (the only allowed size for a basis) which is either a natural number or an infinite cardinal. For brevity, I will use $n$ for $\dim V$.
There are a few important theorems at play here:
Theorem 1: Adding $0$

Suppose that $n=x+y$ for cardinal numbers $n$, $x$, and $y$. Then if $x=0$, $y=n$. (This could be written more simply as $0+n=n$, or similar.)

Theorem 2: Subtracting $n$

Suppose that $n=x+y$ for cardinal numbers $n$, $x$, and $y$, with $n$ finite. Then if $y=n$, $x=0$.

This theorem fails if $n$ is infinite, and it can do so in a very concrete way. If you remove one element from an infinite set of size $n$, then you still have an infinite set of size $n$ left over.
Theorem 3: A theorem about dimension

If $n$ is finite, then the only $n$-dimensional subspace of $V$ is $V$ itself.

Proof: Essentially, a linearly independent set is either already a basis for $V$, or can be extended by choosing independent vectors until you reach a basis for $V$. Extending set of $n$ vectors would give you at least $n+1\ne n$ vectors (see Theorem 2) which is too many; a basis for the subspace must be a basis for $V$.$\square$
This theorem fails if $n$ is infinite, for the same reason that Theorem 2 fails in that case. If you take a basis for $V$, and remove, say, finitely many vectors from it, then you have a basis for a proper subspace of $V$ that has the same dimension.
Theorem 4: Rank-Nullity

$n=\dim \ker T+\dim \mathrm{im}\,T$.

The rank-nullity theorem still holds even when we may be talking about infinite cardinals.
Theorem 5: Your corollary part 1

If $n$ is finite and $\dim W=n$, then for any linear $T:V\to W$, if $T$ is one-to-one then $T$ is onto.

Proof: If $T$ is one-to-one then $\dim \ker T=0$ so that $\dim \mathrm{im}\,T=n$ by theorem 1. By theorem 3 (here we use finiteness of $n$) this forces $T$ to be onto. $\square$
This reliance on finiteness is unavoidable. right-shift is one-to-one from a space of one-sided infinite sequences (or similar) to itself, but not onto. In general, if $n$ is infinite then a bijection from "a basis for $V$" to "all but one element of a basis for $W$" generates a linear map akin to right-shift. Thus, this always has counterexamples if $n$ is infinite.
Theorem 6: Your corollary part 2

If $n$ is finite and $\dim W=n$, then for any linear $T:V\to W$, if $T$ is onto then $T$ is one-to-one.

Proof: If $T$ is onto then $\dim \mathrm{im}\,T=n$. By theorem 2 (here we use the finiteness of $n$), $\dim \ker T=0$ so that $T$ is one-to-one. $\square$
This reliance on finiteness is unavoidable. The example in your question is onto but not one-to-one. Another common example is a left-shift operator. In general, if $n$ is infinite then a bijection from "all but one element of a basis for $V$" to "a basis for $W$" generates a linear map akin to left-shift if you send the remaining basis element of $V$ to $0_W$. Thus, this always has counterexamples if $n$ is infinite.

In conclusion, both halves of the corollary you mention have counterexamples no matter how nice spaces you pick $V$ and $W$ to be, and this ultimately boils down to the failure of theorem 2 in the infinite case. No, we cannot generalize.
