Can someone help me set a better topic for my question? I'm not sure how to do it :)
Here's the scenario:
I have two functions that share the same interface:
interface createMailInterface {
to: String,
subject: String,
message: String
}
const createMail = (config: createMailInterface) => {
const {to, subject, message} = config
const mailOptions = {
from: process.env.MAIL_USER_NAME,
to,
subject,
message
}
return mailOptions
}
const sendMail = (config: createMailInterface): void => {
transporter.sendMail( createMail(config), (error, info) => {
if (error) {
logger.error(error)
} else {
logger.info(`Email sent: ${info.response}`)
}
})
}
However, when declaring the sendMail
function, I receive a warning:
Argument of type '{ from: string | undefined; to: String; subject: String; message: String; }' is not assignable to parameter of type 'Options'.
at the location: createMail(config)
So, my question is, how can I utilize the same interface for nested functions like in the example provided above?