typescript type guard with throw