strings: type assert in the generic `nextind`, `prevind` methods (#57608)
The type assertions are valid according to the doc strings of these
functions in the case of `AbstractString`.
Should prevent some invalidation on loading user code.
Fixes #57605
(cherry picked from commit 6c9c336d2acc71ed740b0cc470c0b76bbbda136c)