-
Notifications
You must be signed in to change notification settings - Fork 111
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
Type guard doesn't work properly with unions #742
Labels
bug
Something isn't working
Comments
Thanks for the report! This should also function as a workaround:
|
I like that better, thanks! Incredible library, by the way. Takes a lot of the sting out of large Lua scripts, especially coming from C#, Java, and TS. |
hishamhm
added a commit
that referenced
this issue
Oct 13, 2024
This expands an `is` applied to a union (even in behind an alias) into a chain of `or` tests with individual `is` checks on the types of the union. If the individual entries have __is metamethods, expands their code as well. This implementation is not recursive (i.e. it does not handle unions of unions), but it is a major improvement over the previous behavior. Fixes #742.
hishamhm
added a commit
that referenced
this issue
Oct 16, 2024
This expands an `is` applied to a union (even in behind an alias) into a chain of `or` tests with individual `is` checks on the types of the union. If the individual entries have __is metamethods, expands their code as well. This implementation is not recursive (i.e. it does not handle unions of unions), but it is a major improvement over the previous behavior. Fixes #742.
hishamhm
added a commit
that referenced
this issue
Oct 16, 2024
This expands an `is` applied to a union (even in behind an alias) into a chain of `or` tests with individual `is` checks on the types of the union. If the individual entries have __is metamethods, expands their code as well. This implementation is not recursive (i.e. it does not handle unions of unions), but it is a major improvement over the previous behavior. Fixes #742.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Type guards with unions that include a record (table) will only check for the table. Other values included in the union will not be captured.
Workaround
You can add a manual type guard in place of the union, which then gets inferred, but only if:
elseif
block andif
statement starts with anis
expressionThe text was updated successfully, but these errors were encountered: