Support non-structural (nominal) type matching #933
Labels
duplicate
This issue or pull request already exists
good first issue
Good for newcomers
invalid
This doesn't seem right
question
Further information is requested
wontfix
This will not be worked on
Feature Request
Hi! First of all, congratulations on this project. It's amazingly well structured.
I started using it for one of my projects where I use Nominal typing (aka branded typing). Since typescript is structural, I am mimicking it using an intersection of primitive type and object (See https://twitter.com/mattpocockuk/status/1625173884885401600?lang=es). For example:
There are other ways though, to approach this. https://michalzalecki.com/nominal-typing-in-typescript/
The problem
The problem I am having is that when I try to use typia to compile the above example, I am getting a
nonsensible intersection
error.Would it be possible to have some "special" Nominal type like
typia.Nominal<T extends string | number>
that allows for this kind of behavior.Approach ideas
I am thinking the metadata constructors could identify this special case (using unique symbols as the object maybe for more safety):
I think Branded types are a very common artifact in a lot of repositories and it's worth exploring it.
Let me know what do you think and if can be of any help.
Edit: I don't think this should affect validation at runtime (if the Nominal type extends primitive string, the validation should check that the input is a string).
The text was updated successfully, but these errors were encountered: