samchon / typia

Super-fast/easy runtime validations and serializations through transformation
https://typia.io/
MIT License
4.31k stars 148 forks source link

Typia tag's information are gone when we place type in variable declaration side instead of in generic function #1145

Closed ryoppippi closed 2 weeks ago

ryoppippi commented 2 weeks ago

Bug Report

πŸ“ Summary

Write a short summary of the bug in here.

Write detailed description in here.

When placing type to the variable side instead of generic function, the basic type information is successfully inferred, but tag's information is gone

⏯ Playground Link

https://typia.io/playground/?script=JYWwDg9gTgLgBDAnmYBDANHA3g1BzAZzgF84AzKCEOAIiRVRoG4AoF4AOxgFMozUAxtzgBJALLcQAI17YWcOMAAmALjgEYUTnjgAyXIQB0AMWghUMADw0ArjeU0AfKwUdUIbmo1aOeVsTYWAQgODTgPaVkAXjkFZTUAcgALbgAbVIgE9Hk4Nw9EgCkIJI4EllI2YND4EDVxSRkoOBj6NENUAgJeGAAKCMaASiCQgghU7kMMvD6BuAB6ObhLAFo4JQhuIg4IeBgkygB3OFQOOF5KKEqRmoB9ZoRkNo6u2Et6yKhHPobeIarR8aTCDTEA3WYLJarPaHIgnM5QC7HIjcAAeYG4Ah4SiUQA Visit above playground and write code occuring the bug.

πŸ’» Code occuring the bug

import typia, { tags } from "typia";

interface IMember {
  id: string & tags.Format<"uuid">;
  name: string;
}

const member = {
  id: 'hello',
  name: 'John'
} 

const m: IMember = typia.assert(member)
console.log(m) // <- does not throw an error

const m_ = typia.assert<IMember>(member)
console.log(m_) // <- throws an error as expected
samchon commented 2 weeks ago
image

When you move the mouse pointere up to the typia.assert(member statement, its implicit generic type is actually one of object literal expression type. So this is not a bug, but a spec.

If typia makes the statement to be asserted by IMemeber type by analyzing the binary expression statement and the type of operand (const m: IMember), it is violating the TypeScript compiler's default behavior.

Also, current typia is just analyzing the source code in the function call expression level. To make accomplish this issue, I have to analyze parent statement cases of the function call expression, and it would be a huge job for typia.

ryoppippi commented 1 week ago

@samchon Thank you for your explanation.

I got it thank you as always