Cannot read property 'type' of undefined