hegel
hegel copied to clipboard
Expose $StrictUnion and similar types as generic
Hey @JSMonk
Would it make sense to expose $StrictUnion as a generic so it could be used by end users?
That would simplify the syntax end users would have to necessarily use. In my case I'm transpiling a GUI Language to js, and I don't want to add Union operator since that would increase the syntax end users have to learn. I found $Intersection, but no corresponding $Union.
describe("$StrictUnion", () => {
// todo make it work with
beforeAll(async () => {});
test("allows parseing of generic $StrictUnion", async () => {
const sourceAST = prepareAST(`
type U = $StrictUnion<bigint | number>
const a: U = 2;
`);
const [[actual], errors] = await createTypeGraph([sourceAST]);
console.log(actual, errors)
expect(errors.length).toEqual(0);
}, 5000);
});
Hi @abhishiv.
Sounds good, I think we can do it.
But, I need to mention that $StrictUnion works a little bit differently than a simple union.
The difference can be shown by the next case:
function union(a: bigint | number) { }
function strictUnion(a: $StrictUnion<bigint | number>) { }
const value: bigint | number = 2n;
union(value) // Ok
strictUnion(value) // Error