Skip to content

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

Open
aymather wants to merge 1 commit intojackbearheart:masterfrom
aymather:add-domain-to-parse-single-emails
Open

bug fix: added domain as part of the ParsedGroup return type#51
aymather wants to merge 1 commit intojackbearheart:masterfrom
aymather:add-domain-to-parse-single-emails

Conversation

@aymather
Copy link
Copy Markdown

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 = 'aymather@gmail.com'
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
Copy Markdown
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