typia icon indicating copy to clipboard operation
typia copied to clipboard

Integer string passes floating decimal string

Open miyaji255 opened this issue 1 year ago • 6 comments

Bug Report

📝 Summary

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

  • Typia Version: v6.5.4
  • Expected behavior: Only pass integer string (such as "1")
  • Actual behavior: Also pass 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 !!

miyaji255 avatar Jul 22 '24 08:07 miyaji255

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.

samchon avatar Jul 22 '24 09:07 samchon

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?

miyaji255 avatar Jul 22 '24 11:07 miyaji255

@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

ryoppippi avatar Jul 22 '24 18:07 ryoppippi

@miyaji255 Good point, will you challenge this issue?

samchon avatar Jul 23 '24 08:07 samchon

Sorry, it's hard for me to do.

miyaji255 avatar Jul 23 '24 11:07 miyaji255

If it becomes possible, it is okay to challenge.

I'm not affordable to develop this feature.

samchon avatar Nov 15 '24 06:11 samchon