# Missing number, treated as zero when renewing enumerate \item and using hyperref [duplicate]

When I tried to integrate the answer for my question How to recognize the enumerate shortlabels in my custom environment? on my thesis document, latex throwed this error:

main.tex:26: Missing number, treated as zero
main.tex:26: Missing \endcsname inserted
main.tex:26: Missing number, treated as zero


After two hours, I managed to create a minimal example reproducing this error:

\documentclass[12pt]{article}
\errorcontextlines 10000
\usepackage[shortlabels]{enumitem}
\usepackage{hyperref}

\def\renewenumerateoptionalitem{%
\renewcommand{\item}[1][]{%
\refstepcounter{enumerateoptionali}% increment the counter
}%
}

\newlist{enumerateoptional}{enumerate}{1}
\setlist[enumerateoptional]{
before=\renewenumerateoptionalitem,
label=\arabic*,
nosep,
labelindent=20mm,
leftmargin=*,
}

\begin{document}
\begin{enumerateoptional}[1.]
\item[Some first] item one
\item[Some second] item two
\end{enumerateoptional}
\end{document}


If you run this, you will get the error main.tex:26: Missing number, treated as zero. The line 26 is the first \item[Some first] item one on the enumerateoptional list.

If you comment the line \usepackage{hyperref}, everything works fine. You can also comment the line before=\renewenumerateoptionalitem, and keep enabled the hyperref package and everything will also work fine too.

After looking into the hyperref package code I found this:

\let\H@item\item
\newcounter{Item}
\def\theHItem{\arabic{Item}}
\def\item{%
\@hyper@itemfalse
\if@nmbrlist\@hyper@itemtrue\fi
\H@item
}


It seems hyperref is also redefining \item to something. How can I integrate the How to recognize the enumerate shortlabels in my custom environment? answer with the hyperref package?

Related questions