Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!: throw error with out of bounds integer values, optionally wrap into DsInt or provide a custom 'integerValue' type cast options #516
feat!: throw error with out of bounds integer values, optionally wrap into DsInt or provide a custom 'integerValue' type cast options #516
Changes from 20 commits
834d9a3
64bd8df
5206576
21ade5e
86baea7
8938cc3
8d93873
c9f7946
d24e515
aab5bac
ba4a314
536ac14
063777e
a2eb3e3
2c9ee4e
c4d944e
de30699
d9d0d80
bad51b3
66574dc
aa2a4ca
c64b6fa
58d9767
3d4f8ba
7c366cc
f353bdf
08f6fa3
96b0043
98f0491
f856765
05968bd
e59dd2d
832d31b
aeda4f4
a193365
6b440f5
ae1d249
ecde411
db6fb32
0d277c1
87792e6
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 think it's fair to just do
this.typeCastProperties = arrify(typeCastOptions.properties)
, even if it's empty 🤷♂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 won't work.
arrify
will always return an array (empty) even iftypeCastOptions.properties
is undefinedA few lined down the logic is
undefined
typeCastOptions.properties
will result in custom casting everyintegerType
entity.property
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.
We can make this type-safe for typescript users by making this class generic on the return type of
valueOf()
:We'll also be able to make
integerTypeCastFunction
type-safe by makingIntegerTypeCastOptions
generic: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.
Nevermind folks.. It's not possible to override the return type of
valueOf()
to the generic type sinceInt
inherits fromNumber
. Typescript really dislike type-hacking..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.
This also means Typescript users would have to coerce the type returned by
valueOf()
: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 might be a bit more readable to ask exactly what we're wondering:
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.
shouldCustomCast
is a better namethis.typeCastFunction
is not a function.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 first reason I thought to suggest this change was due to the
this.typeCastFunction ? true : false
, which is somewhat unusual-- that is coercing the type based on if it's not undefined/null. For readability, I would rather see it say exactly what we're wondering: "We should custom cast the integer if the user gave us a function", vs "We should custom cast the integer if the user gave us a non-null argument".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.
Got it.
My line of thought was, since we already weeded out anything but a
function
, at this point the value ofthis.typeCastFunction
can only be afunction
.But for code readability purposes it makes sense.
Fixed 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.
Up for debate, but newlining here might print better:
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 think this line needs to drop one down.
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 think
typeCastOptions
is optional, so it should be bracketed. And thentypeCastOptions.integerTypeCastFunction
is required within that object, so I don't think it should be bracketed. I'm not sure that's true, though!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.
Drop one line, and same concerns about where to bracket to denote optionality.
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
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.
This is a comment about line dropping and brackets.
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
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 think the first sentence can be changed to.
Configuration to convert values of
integerValue
type to a custom value.