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

Typescript definitions for SMTPServerSession.user possibly incorrect #165

Open
penguoir opened this issue May 23, 2021 · 2 comments
Open

Comments

@penguoir
Copy link

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

  • Change the type definitions from string to any.
  • Change the type of SMTPServerSession.user to be the same as whatever type was passed through in onAuth.

Thanks!

@penguoir
Copy link
Author

A workaround:

(session.user as unknown as Account).doStuff()

@penguoir
Copy link
Author

Any next steps I could take?

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

1 participant