more type safety for ofType and cast functions