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

feat(ts-gen): typeguard helpers for unions #281

Merged
merged 1 commit into from
Oct 14, 2023
Merged

feat(ts-gen): typeguard helpers for unions #281

merged 1 commit into from
Oct 14, 2023

Conversation

andrewmd5
Copy link
Contributor

@andrewmd5 andrewmd5 commented Oct 14, 2023

this change introduces helper functions that allow you to identify the underlying type of a union in a way that populates information to the type system.

const test = Test.fromA({hello: "world"});
if (test.isA()) {
    // typescript knows that 'value' is 'A'
    console.log(test.value.hello)
   // it also knows that 'data' is { discriminator: 1, value: IA }
    console.log(test.data.value.hello)
}

this change introduces helper functions that allow you to identify the underlying type of a union in a way that populates information to the type system.
@andrewmd5 andrewmd5 merged commit cf3ac79 into master Oct 14, 2023
8 checks passed
@andrewmd5 andrewmd5 deleted the type-guard branch October 14, 2023 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant