-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Bug with intersection types #1166
Comments
Fix #1166: nonsensible intersection type case
Thank you very much for your response and especially for adding an exception in problematic cases already, @samchon. This will help developers to earlier recognize this issue if they are affected. However, I hope I can quickly resolve the small misunderstanding around An example variable which can be assigned to this type is included in my original bug report namely Moreover, the type StringArray = string[] & any[];
const testArray: StringArray = ["foo_bar_art"]; or type StringArray = ("case1"|"case2")[] & ("case2"|"case3")[];
const testArray: StringArray = ["case2"]; As mentioned in the original bug report: sometimes developers cannot control the types which they have to use for the intesection, e.g. because the types originate from an OpenAPI type export. Thus, it's not possible to simplify these cases in the code before using typia. Hence, it would be great if you could please reopen this issue - maybe for your backlog - and in a future version somehow replace the exceptions with a working validation. Thank you very much in advance! |
I think you're misunderstanding the TypeScript intersection type. Your example codes are actually nonsensible. At first, rather than The second case is the same. |
Also, I repeat that, If the |
Thanks for your response but I think we still have a major misunderstanding here, I guess we are mixing up intersection types with union types. Let me please explain my arguments again step by step with examples from the TypeScript Playground:
Thus,
In a nutshell, I hope I was able to convince you that these intersection types are valid TypeScript types and not "nonsensible" and should thus please be supported by Typia in the long run. |
Bug Report
First of all, thanks a lot for all the hard work on typia! This bug report revisits a variant of issue #856 about better support for intersection types.
We recently encountered the problem that typia does not correctly apply the
is
-validation when some specific intersections exist somewhere nested in the type to be checked.💻 Example
Originally our problem concerned the intersection of arrays in some property of an object, but it turns out that even much simpler intersections are also affected. Thus, the following example with template strings shows a very simplified case and can be tested in typia's playground ⏯ here:
📝 Problem circumstances
The different types in the intersection, i.e.
Art
andBar
in the example above, may have originally come from external sources such as an OpenAPI type export, and are typically not under our control, or we may not even know exactly what they contain. Thus, the ad hoc workarounds mentioned in the original issue #856 - such as using generics orOmit
- will usually not work here. Moreover, setting theis
-validation result to false in the above example clearly contradicts TypeScript logic, since "bart" is successfully assigned totestString
with typeArtBar
. Thus, we still have the impression that typia's behavior here is a bug and not "invalid" and not "wontfix" as mentioned in the original issue #856.💡 Suggestion
Consequently, we would suggest as an improvement for typia that for intersection types (especially in cases without other complications like generics): try to somehow check each part of the intersection independently first and then combine the results with logical
AND
.If this bug fix is not possible quickly, then it would be great if - as a first, maybe temporary fix - typia could somehow detect such problematic cases and then avoid assigning a boolean value to the
is
-validationresult
at all. Instead, maybe temporarily returnundefined
(or even throw an error), so that we typia-users know that we have to try to use other workarounds until this bug is fixed.Such a temporary fix might also be necessary for the
random
-generator on intersection types, because this generator seems to be broken on these intersection types, like theArtBar
type from above: It returns a complex object which is clearly not a simple string:Thank you very much already in advance. ❤️
The text was updated successfully, but these errors were encountered: