-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat: update adds improved jsdoc based message #173
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
const isProduction: boolean = process.env.NODE_ENV === 'production'; | ||
const prefix: string = 'Invariant failed'; | ||
|
||
// Throw an error if the condition fails | ||
// Strip out error messages for production | ||
// > Not providing an inline default argument for message as the result is smaller | ||
/** | ||
* __invariant__ | ||
* | ||
* The `invariant` function takes a value, and if the value is falsy then the `invariant` function will throw. If the value is truthy, then the function will not throw. | ||
* | ||
* @param {boolean} condition A boolean condition - if falsey will thrown an error. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah this needs to be corrected - will address |
||
* @param {(string|() => string)} message The message provided to accompany the invariant. Can provide a string, or a function that returns a string for cases where the message takes a fair amount of effort to compute. | ||
* | ||
* @returns {asserts condition is true} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. asserts condition is truthy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can certainly add the explanation as an annotation tho next to it. |
||
* @example | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haha yeah. Playful but I think it helps to make it really clear how to use the fn :) |
||
* ```tsx | ||
* import invariant from 'tiny-invariant'; | ||
* | ||
* // throws when 1 no longer equals 1 | ||
* invariant(1 === 1, 'Maths is broken'); | ||
* ``` | ||
*/ | ||
export default function invariant( | ||
condition: any, | ||
// Can provide a string, or a function that returns a string for cases where | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now covered directly in the jsdoc |
||
// the message takes a fair amount of effort to compute | ||
message?: string | (() => string), | ||
): asserts condition { | ||
if (condition) { | ||
|
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.
have also added the same jsdoc to the flow package