Consider this example:
type SomeType = {
paymentData?: {
paymentMethod?: string;
}
}
const someObj: SomeType = {};
const someTest = ['creditCard', 'payPal'].includes(someObj.paymentData?.paymentMethod);
This doesn't work in TypeScript because it infers the type of the array elements to be string so it requires the value used in with the includes function to also be of type string, but someObj.paymentData?.paymentMethod is possibly undefined aka the type is string | undefined. I cannot use the non-null assertion operator (!) as it can't be used after optional chaining.
JavaScript-wise it's perfectly fine if the includes checks with undefined, just TypeScript is unhappy about it. What are nice ways to satisfy TypeScript here?