smtp/client: re-strengthen send & sendAsync types

This commit is contained in:
Zack Schuster 2022-04-14 10:17:51 -07:00
parent 5ee7d3b3b8
commit 652684486c
1 changed files with 11 additions and 9 deletions

View File

@ -45,14 +45,15 @@ export class SMTPClient {
/**
* @public
* @param {Message} msg the message to send
* @param {MessageCallback} callback .
* @template {Message | MessageHeaders} T
* @param {T} msg the message to send
* @param {MessageCallback<T>} callback receiver for the error (if any) as well as the passed-in message / headers
* @returns {void}
*/
public send(
msg: Message | MessageHeaders,
callback: MessageCallback<Message | MessageHeaders>
) {
public send<T extends Message | MessageHeaders>(
msg: T,
callback: MessageCallback<T>
): void {
const message =
msg instanceof Message
? msg
@ -81,10 +82,11 @@ export class SMTPClient {
/**
* @public
* @param {Message} msg the message to send
* @returns {Promise<Message>} a promise that resolves to the fully processed message
* @template {Message | MessageHeaders} T
* @param {T} msg the message to send
* @returns {Promise<T>} a promise that resolves to the passed-in message / headers
*/
public sendAsync(msg: Message | MessageHeaders) {
public sendAsync<T extends Message | MessageHeaders>(msg: T) {
return new Promise<Message>((resolve, reject) => {
this.send(msg, (err, message) => {
if (err != null) {