samchon / typia

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

Integer string passes floating decimal string #1175

Open miyaji255 opened 1 month ago

miyaji255 commented 1 month ago

Bug Report

📝 Summary

`${number & tags.Type<"int32">}` passes decimal string (such as "0.1")

⏯ Playground Link

https://typia.io/playground/?script=JYWwDg9gTgLgBDAnmYBDANHA3g1BzAZzgF84AzKCEOAIiRVRoG4AoF+gUzmADsYBlGFDgBeOAAMAJFh4BXEACMOwgGS5CAOgAqyDgB4avGAGYATDQB8xcWwDGEHgXgA3VABs4ohMjQaoqHgATKj0jQSgLAAoASiY4AHp42gAGGkwaAEYaOA1clntHeFsACw5bAGsMr3pfYAJQvnComlTYhKShWQ58hyc4ErLy02qfVA06hoEhZuSNLLbEhCguuD0xACFZPDgAQh27Xog3Dg03CDxIrBZPVzd0a-7Sioz7zwGK0xZiNpYgA

💻 Code occuring the bug

import typia, { tags } from "typia";

type intStr = `${number & tags.Type<"int32">}`

const val  = typia.random<intStr>(); // "0", "1" ...
const check1 = typia.is<intStr>("0"); // true
const check2 = typia.is<intStr>("0.1"); // true <= Bug !!
samchon commented 1 month ago

Unfortunately, template literal string type cannot utilize type tags.

It's because TypeScript compiler API cannot recognize the intersection tag type in the template literal type.

miyaji255 commented 1 month ago

That's unfortunate. Since typia.random<intStr>() was outputting correctly, I thought it could be obtained. Is there a way to treat strings without other characters (for example, `${boolean}`, `${number & tags.Type<"int32">}`) as a special case?

ryoppippi commented 1 month ago

@samchon I found that ts compiler can handle the intersection tag type in the template literal since v5.1! TS5.1

Screenshot 2024-07-22 at 19 28 08

TS5.0

Screenshot 2024-07-22 at 19 27 55

The interesting thing is that anoter library ts-runtime-checks has the same issue

samchon commented 1 month ago

@miyaji255 Good point, will you challenge this issue?

miyaji255 commented 1 month ago

Sorry, it's hard for me to do.