-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Port utils to @flow. #935
Port utils to @flow. #935
Conversation
src/utils.js
Outdated
return indexOf(list, elem) !== -1; | ||
}; | ||
|
||
/** | ||
* Provide a default value if a setting is undefined | ||
*/ | ||
const deflt = function(setting, defaultIfUndefined) { | ||
const deflt = function<T>(setting: T | void, defaultIfUndefined: T): * { |
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.
Unfortunately, I couldn't use T
as the output type itself as I ran into facebook/flow#5022.
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.
Can you add a comment with a link to the issue?
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.
Done.
src/utils.js
Outdated
return indexOf(list, elem) !== -1; | ||
}; | ||
|
||
/** | ||
* Provide a default value if a setting is undefined | ||
*/ | ||
const deflt = function(setting, defaultIfUndefined) { | ||
const deflt = function<T>(setting: T | void, defaultIfUndefined: T): * { |
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.
Can you add a comment with a link to the issue?
src/utils.js
Outdated
@@ -55,18 +56,16 @@ const ESCAPE_LOOKUP = { | |||
|
|||
const ESCAPE_REGEX = /[&><"']/g; | |||
|
|||
function escaper(match) { | |||
// Type-safe only if the input string matches ESCAPE_REGEX. | |||
function escaper(match: string): string { |
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.
It's possible that escaper
could return undefined
.
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.
Not given the comment I'd added above escaper()
. It's used only for escape()
. In fact, I removed this function and just inlined it where it's used.
src/utils.js
Outdated
@@ -27,21 +28,21 @@ const indexOf = function(list, elem) { | |||
/** | |||
* Return whether an element is contained in a list | |||
*/ | |||
const contains = function(list, elem) { | |||
const contains = function<T>(list: Array<T>, elem: T) { |
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.
The return value for this could be boolean
.
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.
Whoops. I wish flow would catch missing types.
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.
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.
Yes please!
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.
LGTM
No description provided.