Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branded types support #1066

Open
rivatove opened this issue Oct 13, 2024 · 2 comments
Open

Branded types support #1066

rivatove opened this issue Oct 13, 2024 · 2 comments
Labels
invalid This doesn't seem right wontfix This will not be worked on

Comments

@rivatove
Copy link

Feature Request

Nestia throws the following error on branded properties:

- number & Brand<"ProductPrice">:
- nonsensible intersection

With the ProductPrice being of the following type (with a standard Branded implementation):

type ProductPrice = Branded<number, 'ProductPrice'>;

I wonder if there is a way for Nestia to reduce the above type to just number?

Maybe we could somehow define the Brand wrapper to make Nestia ignore intersections with that type? Or to define the internal brand property key (in my case __brand) to ignore?

@samchon
Copy link
Owner

samchon commented Oct 13, 2024

Branded type is not supported, because it needs re-interpret type casting, the type unsafe strategy.

@samchon samchon added invalid This doesn't seem right wontfix This will not be worked on labels Oct 13, 2024
@rivatove
Copy link
Author

Branded type is not supported, because it needs re-interpret type casting, the type unsafe strategy.

I'm aware it requires type casting. Hence it shouldn't be enabled by default.

But branded types are widely used. So an escape hatch is useful because they're gonna be used anyway. And having a built in way to do that increases Nestia's appeal.

I dont see what would be the harm in defining an object key in the config, which if an object has, and the object is a part of an intersection, makes the object get discarded from the intersection by Nestia.

It's a completely opt in behavior and the user can be made aware of the risks if the key is mistyped or not unique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants