Fix spell target and cast type Closes #17623 (cherry picked from commit 10ac7a06dee726f4a8a6a33dba6533cf88eb0e29)