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

bug fix: added domain as part of the ParsedGroup return type #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aymather
Copy link

I'd like to suggest adding the domain to the ParsedGroup return type because this basic example isn't working as expected.

import { parseOneAddress } from 'email-addresses'

let email: string = '[email protected]'
const parsed = parseOneAddress(email)
console.log(parsed.domain)

It is telling me:

Property 'domain' does not exist on type 'ParsedMailbox | ParsedGroup'.
  Property 'domain' does not exist on type 'ParsedGroup'.ts(2339)

@jackbearheart
Copy link
Owner

It's true that a "group" does not have a "domain" associated with it. I don't think adding a property that doesn't exist will be good for TS users who want accurate types. However, I see that this is inconvenient because the return types of all the functions include ParsedMailbox | ParsedGroup and then you have to handle the case of there being a group. I discussed this a bit here: #41 (comment)

I think the real solution is creating a parseOneMailbox function with the return type ParsedMailbox | null, because this is a very common use case.

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

Successfully merging this pull request may close these issues.

2 participants