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

Can't access email.to.text - Property 'text' does not exist on type 'AddressObject | AddressObject[]' #320

Open
ufo512 opened this issue Oct 18, 2022 · 5 comments

Comments

@ufo512
Copy link

ufo512 commented Oct 18, 2022

Hi, how can I get the text value of an email recipient?

I did it successfuly for a sender:

const email = await mailparser.simpleParser(stream);
const from = email.from?.text ?? "";

but when I try to do that for "to":
const toText = email.to?.text ?? "";
I get this error:

Property 'text' does not exist on type 'AddressObject | AddressObject[]'.
  Property 'text' does not exist on type 'AddressObject[]'.

After displaying a whole email object (console.log(email)) i can see that I should be able to access to, just as from:

. . .
  to: {
    value: [ [Object] ],
    html: '<span class="mp_address_group"><a href="mailto:abc@localhost" class="mp_address_email">abc@localhost</a></span>',
    text: 'abc@localhost'
  },
  from: {
    value: [ [Object] ],
    html: '<span class="mp_address_group"><span class="mp_address_name">Test</span> &lt;<a href="mailto:test@example.com" class="mp_address_email">test@example.com</a>&gt;</span>',
    text: 'Test <test@example.com>'
  },
  html: false
. . .

What might be the problem here? Am I using wrong keywords?

@vAugagneur
Copy link

same probleme

@liesislukas
Copy link

image

image

@jekozyra
Copy link

The issue is that the types here for to, cc, and bcc are incorrect. They should be AddressObject | undefined.

AddressObject[] type is is what is giving you the type error, because it is an array of AddressObjects. To satisfy typescript, you have to handle both the case where to could be AddressObject[] or the case where to could be AddressObject, even though the former case should never occur. The relevant code for the address parsing is here and here.

@DreAmigo
Copy link

Did we get any resolution on this?

@hlamber
Copy link

hlamber commented Mar 29, 2024

I search solution too

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

6 participants