samchon / typia

Super-fast/easy runtime validators and serializers via transformation
https://typia.io/
MIT License
4.47k stars 154 forks source link

`typia.tags` intersection Type Problem in Conditional type. #1275

Closed 8471919 closed 4 days ago

8471919 commented 4 days ago

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.

`npm install --save-dev typia@next`

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.

When I make intersection type using more than two typia.tags, in Conditional type, like T extends tags.Format<'uuid'> ? true: false the made intersection type always return true.

type IsDate<T> = T extends tags.Format<'date-time'> ? true : false;

// should be false, but represented true
type A = IsDate<tags.MaxLength<4> & tags.MinLength<3>>;

// should be false, but represented true
type B = IsDate<tags.Format<'uuid'> & tags.Type<'int32'>>;

type IsInt32<T> = T extends tags.Type<'int32'> ? true : false

// should be false, but represented true
type C = IsInt32<tags.MaxLength<4> & tags.MinLength<3>>;

// should be false, but represented true
type D = IsInt32<tags.Format<'uuid'> & tags.Type<'int32'>>;

I wanna make this type. This type is the string & tags.Format<'date-time'> type of transforming user defining entity, not auto generated prisma interface,


export type TransformEntity<T> = {
  [P in keyof T]: Transform<T[P]>;
};

type Transform<T> =
  T extends tags.Format<'date-time'>
    ? Date
    : T extends tags.Format<'date'>
      ? Date
      : IsStringLiteral<T> extends true
        ? string
        : TransformEntity<T>;

type IsStringLiteral<T> = [T] extends [string] ? true : false;

but...

image

null | ('${number}' & tags.MaxLength<4> & tags.MinLength<4>) type is infered Date | null

⏯ Playground Link

https://typia.io/playground/?script=JYWwDg9gTgLgBAbzjAhgcwM5wL5wGZQQhwBEMAnmMCiQNwBQ9FYApnAJIYAiKMLAPABUAfHAC8cQXBYAPPgDsAJllSYAdADFoIXvwDki3iwC0MUCz2iA-MigBXNgC58KADYYWDegHpvcDAAWEHauinAARmx4bh4ANBF28FAsYMke8nxhMPYsTJRsAILiHNxG-KoYagCyKDIAMizyaDAB-AAsogBkyOiVVcDyDU0t-ADMwsJevv5BIWGRLu4s8eGJcMmpLOmZtg55rHAAQsWcPHzlvZraunp2dsCKlnDdFWqC+foDMKMATJaTjH2bE47AyvyEogkUlkCmUPXU71YnzBf2suyciw8jGmgWCoQiURiywSSRSaUaO2ye2YbAAwicMKDvj8LuoavVGs1Wh1nvC+gMhlyxhMpn5cXMCZjiatSZttiwsjkgXAuAymeDXlooDoYPo7g8ni9LoiBHovr9-l56EA

8471919 commented 4 days ago

I understood why this is not work. so close this issue.