Typescript Check Variable Undefined