nodemailer / smtp-server

Create custom SMTP servers on the fly
Other
846 stars 145 forks source link

Typescript definitions for `SMTPServerSession.user` possibly incorrect #165

Open penguoir opened 3 years ago

penguoir commented 3 years ago

Let me know if this isn't the right repo to put this issue.

In the onAuth handler, I pass an object through the user parameter. It says in the documentation that this is fine.

onAuth (auth, session, callback) {
  const account = getAccountFromSMTP(auth)
  // ...
  return callback(null, { user: account })
}

But then, when I use this account in the onRcptTo handler, Typescript tells me that user is a string!

onRcptTo (address, session, callback) {
  const account = session.user
  account.doStuff() // ERROR: Property 'doStuff' does not exist on type 'string'.
}

This makes sense, as that's what's written in the type definitions:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a23f844346b0013a6bbc74ef0ddea16c127e815f/types/smtp-server/index.d.ts#L119

Possible solutions

Thanks!

penguoir commented 3 years ago

A workaround:

(session.user as unknown as Account).doStuff()
penguoir commented 3 years ago

Any next steps I could take?