Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MessageAttachment stream - type should be "Readable" not "ReadStream" #261

Closed
lselden opened this issue Jun 25, 2020 · 2 comments
Closed

Comments

@lselden
Copy link
Contributor

lselden commented Jun 25, 2020

in v3.2 the "stream" arg for a MessageAttachment expects fs.ReadStream. But that means other types of streams (not from filesystem) will throw an error. Instead, you should use the type import {Readable} from "stream" - or even the lower level NodeJS.ReadableStream, which is all that you need to ensure the type has the .readable property and can be piped.

Relevant line:

https://github.com/eleith/emailjs/blob/v3.2.0/smtp/message.ts#L51

Reproduce Error:

import zlib from 'zlib';
import fs from 'fs';
import { MessageAttachment } from 'emailjs';

const attachment: MessageAttachment = {
    // this will throw typescript type error, because createGzip() resolves to Transform type (which extends Readable)
    stream: fs.createReadStream(logpath).pipe(zlib.createGzip())
}
@zackschuster
Copy link
Collaborator

i went with stream.Readable, mostly to keep type imports consistent. see smtp/message: fix attachment stream type cb69297.

thanks for the heads-up :)

@zackschuster
Copy link
Collaborator

should be fixed as of 3.2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants