In one of my Typescript projects, I am faced with the task of constructing a dynamic 'if' statement based on the data received from an object. The number of conditions in this 'if' statement should match the number of properties present in the object.
Here is the initial object:
interface EmailParams {
sender?: string,
subject?: string,
fileType?: string
}
let params: EmailParams = {
sender: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="720617010632151f131b1e5c111d1f">[email protected]</a>"
}
This is the condition that needs to be met:
if (test1.from.toUpperCase() == params.sender?.toUpperCase())
If there are changes made to the object, here is the updated version:
interface EmailParams {
sender?: string,
subject?: string,
fileType?: string
}
let params: EmailParams = {
sender: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c38293f380c2b212d2520622f2321">[email protected]</a>",
subject: "data"
}
The new 'if' statement should now look like this:
if (test1.from.toUpperCase() == params.sender?.toUpperCase() &&
test1.data.toUpperCase() == params.subject?.toUpperCase()
)