add type "function" to castTo method