-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
Array of unions incorrect assertion #885
Comments
Hard to understand the type. Can you reproduce it with much simpler type? |
@samchon please let me know if this is any better (also edited the original comment) |
The combination of union and intersection type comes as Need additional investigation. |
@samchon thank you! I will also try to dig through Typia code on my side |
It is because When such duplicated property exists in the intersection type, TypeScript compiler API considers it as import typia from "typia";
export namespace WType {
export type A = "A";
export type B = "B";
export type C = "C";
}
export type W = {
id: string;
type: T;
} & (AExt | BExt | CExt);
export type AExt = {
a: {
children: Array<
W<WType.B>
| W<WType.C>
>;
};
};
export type BExt = {
b: {};
};
export type CExt = {
c: {}
};
export const data: W<WType.A> = {
id: "1",
type: "A",
a: {
children: [
{
type: 1,
id: "2",
} as any,
],
},
};
const res = typia.validate<W<WType.A>>(data);
console.log(res); // prints failed. |
@samchon thank you for such a quick turnaround! |
Will you try this type? @GoogleFeud |
I think that the |
@samchon not sure why this issue was closed given there is no resolution. @GoogleFeud Subjectively it may seem like a culprit to you, however we have a strong use-case to construct types this way and Typescript allows us to do it so. If you have issues with supporting this case in your library, please let us know - we will be happy to assist. |
Ah, I'm sorry but mis-closed with wrong flag. This issue is not fixable, so that close as not planned. |
Bug Report
📝 Summary
Write a short summary of the bug in here.
Array of union types doesn't get validated properly. As soon as array is wrapped around a singular type (rather than a union of types) - validation works as expected. Even though TypeScript highlights the issue when the data is constructed manually, it would be great to validate the data during the runtime and get the same error (for cases when data is received via an API).
⏯ Playground Link
https://typia.io/playground/?script=JYWwDg9gTgLgBDAnmYBDOAzKERwERIqp4DcAUGQKYAeksclAdgK64DqAKspXAN5kBIAIJwAvPiF4ANIIBCY-LOmCAwgrwrlAXwo068QjzYAeDg2owmAEwDOcTtwB8C-gOBWAXHBswowRgDm5AKGXhzkWnAAZHAAFEIAohZwAD5wsknwaSqZAJTkVLTQBtxwicnirqH2XGCUAHRCwahergIAxgAWwAA2VlBMXkJQUKiIxoICAiYOdfWyjpMCaTO1DSqLU47BWhEFesUIpRkVfILVsw2ywQBGrbtkD4X6R3VwOadV3F6X9SrB7XujwKz0O7QgjB8cCsqBgLXsxl+QmclUE7i8eAAjMoQt8atxGjIBPC2l1ev1BnAANpLNpTaqYolTNyefAAJhxUy0TIAukTucCKODIfABnZxIQ0PUAG6oHruWGURGItaNRyOWIwuH5MjCmwQHoNHoQAKxMX5IA
💻 Code occuring the bug
The expectation for the
$input.a.children[0].type
to be reported as of the invalid type (same as typescript does at compilation time). Currently the success is returned. Interestingly ifWTypeExt.a.children
type is changed toArray<W<WType.B>>
(i.e. removing the union) the validation works as expected.The text was updated successfully, but these errors were encountered: