Skip to content

Fix intersections with primitives to add support for nominal types #120

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MurhafElmasri
Copy link

@MurhafElmasri MurhafElmasri commented Dec 21, 2021

as issue #110 stated mention, typescript-is does not support adding nominal types. while typescript does for example:

type USD={id:'usd'} & number
const usd: USD = 5 as USD  // typescript allow this
const x=5;
console.log(is(<USD>(x)) // --> false

Suggested fix

we can notice that every time we intersect an object with primitive type the return type will the primitive type, So simply what I did is return the that primitive type when ever there is intersection between it and any object

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant