check type before cast