OP's ket first equation$^1$
$$\tag{1} \hat{p}|x\rangle ~=~+i\hbar\frac{\partial |x\rangle}{\partial x}$$
is explained in eq. (7) of my Phys.SE answer herehere. In short, eq. (1) is consistent with the corresponding bra equation
$$\langle x |\hat{p} ~=~-i\hbar \frac{\partial \langle x |}{\partial x} $$
via Hermitian conjugation. The bra equation in turn is related to OP's second equation
$$ \tag{2}\hat{p} ~=~ -i\hbar \frac{\partial }{\partial x} $$
via the standard convention
$$\psi(x)~=~\langle x | \psi \rangle$$
for the wave function.
--
$^1$ Both sides of the ket equation (1) are kets in an appropriate infinite-dimensional vector space. (Warning: not a Hilbert space, cf. e.g. thisthis Phys.SE post and links therein.). One can multiply eq. (1) from left with a bra $\langle \psi |$ [belonging to an appropriate (possibly different) infinite-dimensional vector space] to achieve an equation
$$\hat{p}\psi(x)^{\ast} ~=~\langle \psi |\hat{p}|x\rangle ~\stackrel{(1)}{=}~+i\hbar\langle \psi |\frac{\partial }{\partial x}|x\rangle ~=~+i\hbar\frac{\partial \langle \psi |x\rangle}{\partial x}~=~+i\hbar\frac{\partial \psi(x)^{\ast}}{\partial x},$$
where both sides are complex numbers.