Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Expose $StrictUnion and similar types as generic #331

Open
abhishiv opened this issue Mar 5, 2021 · 1 comment
Open

Expose $StrictUnion and similar types as generic #331

abhishiv opened this issue Mar 5, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@abhishiv
Copy link

abhishiv commented Mar 5, 2021

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);
});
@JSMonk
Copy link
Owner

JSMonk commented Mar 5, 2021

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

@JSMonk JSMonk added the enhancement New feature or request label Mar 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants