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

Ammend typings for better specificity #30

Merged
merged 4 commits into from
Jun 19, 2017

Conversation

wbhob
Copy link
Contributor

@wbhob wbhob commented Jun 11, 2017

No description provided.

@pauloppenheim-gingerlabs
Copy link
Contributor

ParsedEmailOutput would be nice. Why get rid of the module declaration? https://www.typescriptlang.org/docs/handbook/modules.html

@jackbearheart
Copy link
Owner

@pauloppenheim-gingerlabs In #19 someone else suggested removing the module declaration, although that was now over a year ago, and the documentation they link to is no longer there. Any comments? If not, I may as well merge this as is.

@wbhob
Copy link
Contributor Author

wbhob commented Jun 15, 2017

I added the module declaration back

@jackbearheart
Copy link
Owner

@wbhob this looks good. As a typescript user, is it annoying if there are additional properties on the objects that aren't defined in the interface? i.e. does this make it so typescript users have to cast to any to access other properties? If so, we can just define all the properties.

@pauloppenheim-gingerlabs
Copy link
Contributor

If there are properties on the object that are not on the type, yes, accessing them is a build error that requires a cast of some kind to work around.

@wbhob
Copy link
Contributor Author

wbhob commented Jun 15, 2017

Yes, all object properties should be on the interface, or else the compiler will complain. I went solely off the docs for this, so if there are other properties that you know of please add them

@jackbearheart
Copy link
Owner

I added the rest of the properties, and configured some other (in retrospect perhaps odd) behavior of this module like being a function object.

@jackbearheart
Copy link
Owner

As a note for myself (who doesn't use typescript usually) and others, here's how I verified the typings in this branch:

➜  eatest tsc --version 
Version 2.3.4
➜  eatest cat test.ts
// Run this file with:
//  tsc test.ts && NODE_PATH="../emailaddresses/lib" node test.js
/// <reference path="../emailaddresses/lib/email-addresses.d.ts"/>
import emailAddresses = require('email-addresses');

var testEmail : string = "TestName (a comment) <test@example.com>";
console.log(testEmail);

var parsed = emailAddresses.parseOneAddress(testEmail);
console.log(parsed);

var a : string = parsed.parts.name.children[0].name;
console.log(a);

var comment : string = parsed.parts.comments[0].tokens;
console.log(comment);

//

var emailList : string = "TestName <test@example.com>, TestName2 <test2@example.com>";
console.log(emailList);

var parsedList = emailAddresses.parseAddressList(emailList);
console.log(parsedList);

var b : string = parsedList[1].parts.name.children[0].semantic;
console.log(b);

//

var parsedByModuleFxn = emailAddresses({ input: emailList, rfc6532: true });
console.log(parsedByModuleFxn.addresses[0].name);

@jackbearheart jackbearheart merged commit 1f2375c into jackbearheart:master Jun 19, 2017
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.

None yet

3 participants