typescript-is icon indicating copy to clipboard operation
typescript-is copied to clipboard

Fix intersections with primitives to add support for nominal types

Open MurhafElmasri opened this issue 2 years ago • 0 comments

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

MurhafElmasri avatar Dec 21 '21 15:12 MurhafElmasri