-
Notifications
You must be signed in to change notification settings - Fork 12
Refactor for more type safety #11
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
Conversation
|
Also added tslint and followed most of its suggestions. |
|
@seanf do you mind that i invite you as a collaborator ? |
|
@seanf Thank you so much. Awesome refactor.. |
Thanks!
@BANG88 not at all! But please give me some guidance on what I should do (eg with my own code, or with others' pull requests). I think it's always good to have a second person review any code. |
| * @param {string} contents | ||
| * @returns {array} | ||
| */ | ||
| // TODO perhaps we should expose the Message interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BANG88 How would you feel about exposing the Message interface as the return type for the (publicly exported) main method (well, an array of them to be exact)? (As opposed to an array of plain object {}.)
It shouldn't break any consumers, because I believe it's a narrower type, but I'm still very new to TypeScript, so I could be wrong about that. In practice the consumers seem to be plain JavaScript npm scripts (unless they use ts-node), so they probably don't care about types. Still, I like types as documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the types too. If you prefer or think is useful for you please do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it a bit more, I think it would be better if the interface looked more like this:
interface MessageDescriptor {
id: string
defaultMessage: string
description?: string
[key: string]: string; // for any other properties
}Otherwise exposing it won't really add much value.
| "rules": { | ||
| "no-any": true, | ||
| // TODO perhaps we *should* use the 'I' prefix? | ||
| "interface-name": [true, "never-prefix"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BANG88 I wasn't sure if idiomatic TypeScript required "I" interfaces, but the guidelines for TypeScript itself advise against them, so I'm inclined to disallow the I prefix (and remove this TODO comment). Any objection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. this just some coding style not strict rule. for the simple package we do not want too much configurations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BANG88 Well, tslint is going to be strict about this rule. I think I could disable the rule entirely, but I think it's important to be consistent, one way or another. Having some interfaces with I and some without is confusing.
|
@seanf Hey great refactor! <3 |
Sorry, this proved a little larger than expected!
It's mostly refactoring to avoid a cast, to separate JSX from
defineMessagesand fromformatMessage(fewerifs), and to use more meaningful names.But to avoid casting the PropertyAssignment's PropertyName
as anyI had to usetextinstead ofescapedText(I thinkescapedTextmust be non-public compiler API), so we now use the un-escaped text as the message key (which seems like the right thing to do).Also, I changed things a bit so that the object keys for
defineMessages/formatMessagecan now be string/number literals, not just identifiers.It should be mostly logical if you read the commits in order, but let me know if you want it split up or something.