Closed DavidSchmidtPocket closed 7 months ago
Just ran into this as well! 🤯
@DavidSchmidtPocket What did you do to work around this?
@muratgozel Please look into this as it is quite a severe problem imo (that the type definitions / docs are simply wrong)
This is a big deal. Not a usable product for typescript.
Just ran into this as well! 🤯
@DavidSchmidtPocket What did you do to work around this?
@muratgozel Please look into this as it is quite a severe problem imo (that the type definitions / docs are simply wrong)
Sorry, I missed these responses. Found the correct (hidden) api and tsignored it essentially.
body,
to,
subject,
cc,
bcc,
replyToMessageId,
threadId,
}: {
body: string;
subject: string;
to: string[];
cc: string[];
bcc: string[];
replyToMessageId?: string;
threadId?: string;
}) => {
const { userId, currentUserEmail } = await authAndGetCurrentUserEmail();
if (!userId) {
return { status: 401, message: 'User not logged in.' };
} else if (!currentUserEmail) {
return { status: 401, message: 'User email not found.' };
}
const message = createMimeMessage();
message.setSender(currentUserEmail);
message.setTo(to);
message.setCc(cc);
message.setBcc(bcc);
message.setSubject(subject);
if (replyToMessageId) {
message.setHeader('In-Reply-To', replyToMessageId);
message.setHeader('References', replyToMessageId);
}
//message.setMessage('text/plain', 'yo'); // setMessage is not a function
//@ts-expect-error // addMessage works just fine, but typescript doesn't know about it
message.addMessage({
contentType: 'text/plain',
data: body,
});
const res = await gmailFetch(
'https://gmail.googleapis.com/gmail/v1/users/me/messages/send',
{
method: 'POST',
body: JSON.stringify({ raw: message.asEncoded(), threadId }),
},
);
revalidatePath('/');
if (res) {
return { status: 200, message: 'Email sent successfully.' };
} else {
return { status: 500, message: 'Failed to send email.' };
}
};```
hey, mimetext has type definitions inside the package, you dont need to use @types/mimetext
. i should probably make a request for removal from there.
const message = createMimeMessage(); message.setSender('fake@email.com'); message.setTo('fake2@email.com'); message.setSubject('Test Email Please Ignore'); //message.setMessage('text/plain', 'yo'); // setMessage is not a function //@ts-expect-error // addMessage works just fine, but typescript doesn't know about it message.addMessage({ contentType: 'text/plain', data: 'Yo', }); const res = await gmailFetch( 'https://gmail.googleapis.com/gmail/v1/users/me/messages/send', { method: 'POST', body: JSON.stringify({ raw: message.asEncoded() }) }, );
TLDR: the docs suggest using addMessage, but it's not a valid type. setMessage is a valid type, but doesn't actually exist on the message object. There may be other mismatches, but this is the only one I've run into thus far.