Open ryoppippi opened 3 weeks ago
Sorry for not reporting earlier despite being a discoverer (thanks for creating the issue @ryoppippi!).
I usually don't write web code and I am not sure how to fix... oh? Is this your intention here?
{
"plugins": [
{
"transform": "typia/lib/transform",
"undefined": false // !!!
}
]
}
At least, on my particular case I'm testing, it works as expected on is
but not on assert
.
According to the documentation of ITransformOptions
,
there is an issue when validating without allowing superfluous properties.
Let me clarify the situation. The intent of this option is change the behavior of the code below, is it?
interface ISample {
a: number;
}
export const is_ISample = typia.createIs<ISample>();
export const eq_ISample = typia.createEquals<ISample>();
/* import is_ISample, eq_ISample */
console.log(is_ISample({a: 0, b:undefined})); // true
console.log(eq_ISample({a: 0, b:undefined})); // true by default but "undefined":false makes eq_ISample return false.
I think it's type-safe and reasonable, depending on the situation.
But accepting undefined
just when there is a dynamic property easily breaks type-safety.
Perhaps, the target to fix is somewhere around check_dynamic_property
?
Hmm, is
works fine after changing undefined
option to false
but it erroneously accepts invalid inputs with undefined
props on assert
. So, we need to fix something related to error-generating code as well.
I didn't understand more about Typia OPTIONS! So there is undefined option, thank you!
My opinion is clear: undefined
value should not be accepted (unless the value can be undefined
) when a dynamic property can match (regardless of the undefined
transform option).
Bug Report
Note that, the bug you're reporting may have registered in the issues by another user. Even the bug you're reporting may have been fixed in the
@next
version. In such reasons, I recommend you to check the old issues and reproduct your code with the@next
version before publishing the bug reporting issue.When the same error occurs even in the
@next
version, then please fill the below template:📝 Summary
Write a short summary of the bug in here.
⏯ Playground Link
https://typia.io/playground
Visit above playground and write code occuring the bug.
After that, copy and paste link address of that.
💻 Code occuring the bug
suggested solution.
We need to use
Object.hasown
instead ofvalue[key] === undefined
Related
https://x.com/a4lg/status/1805485371494744536 by @a4lg