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
Typia Omits NaN Checks (By Default) #513
Comments
Special functions like As you know, If you want to turn on the Lines 106 to 112 in b2fa3fe
|
@samchon Well, fair enough, however Will close off this issue as it sounds default |
As above statement is not a compile error in Typescript (of course, it is nonsensible), I have to keep current policy. Also, as I've invented this
Therefore, I decided to not use |
@samchon It's fine. I think aligning strictly to the policies of TypeScript is quite reasonable with the configuration overrides, so all good there. But please document the While I do think most people would probably recommend Just on the topic of configurations / performance though, you can actually use the following to have TypeBox adopt TypeScript checking semantics as well. This should let you directly measure AOT and JIT performance for equivalent assertion logic. Both of these are import { TypeSystem } from '@sinclair/typebox/system'
TypeSystem.AllowArrayObjects = true
TypeSystem.AllowNaN = true Would be curious to see the performance cost of Anyway, Good work! Typia's looking good (also, glad you went with name change!) |
Summary
Hey, have noticed Typia doesn't appear to check for
NaN
values. Note thatNaN
(i.e. Not-A-Number) is a unrepresentable / non-computable IEEE754 numeric that can only result in anotherNaN
. JavaScript supportsNaN
as a consequence of IEEE754; and TypeScript interprets it as anumber
static type, but for validation purposes, not validating for it is a very common source of errors.Comparison
Assertion for
NaN
is generally expected for number validation, the following are a list of libraries I've tested so far.Performance
Note, You are almost certainly going to see a performance degradation as a result of implementing this check (which largely accounts for the excessive performance disparity as shown in your projects readme, specifically
ObjectSimple
). However not implementing this check does put Typia at odds with other validators (and probably at odds with the expectations of users).A possible solution may be to make the
NaN
check configurable (as TypeBox has done to get visibility on this disparity) which will allow Typia to keep on with the 15,000x performance claim, but I do think Typia should probably assert forNaN
by default (with a possible--allow-nan
command line option to allow Typia to opt out ofNaN
checks when benchmarking).Micro Benchmark
The following shows the comparative performance with and without the
NaN
check. When factoring the Point3D check for ObjectSimple, that almost certainly accounts for the 12x performance for this object.System
Node: 16.17.1
Typescript: 4.9.5
Typia: 3.5.4
References
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN
https://en.wikipedia.org/wiki/IEEE_754
For consideration
The text was updated successfully, but these errors were encountered: