I find myself in this particular scenario:
const user: UserObj = User.get(userId);
if ([user.foo, user.bar, user.baz].some((k) => !k))
throw new Error(`Missing fields for user ${userId}`);
const createParams: CreateParams = {
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
phone: user.phone,
foo: user.foo,
bar: user.bar,
baz: user.baz
};
My issue here is that foo bar baz
need to be present in CreateParams
. TypeScript is raising errors because those keys are optional in UserObj
. However, I have implemented a .some
check to ensure they exist, but TypeScript still shows errors. How can I prove to TypeScript that these required keys will always be provided?