Replies: 2 comments 3 replies
-
Teal does not do type inference with |
Beta Was this translation helpful? Give feedback.
1 reply
-
Would you be open to narrowing based on type assertions, or is this is a design decision to only narrow based on “is”? Or does is do everything narrowing based on type would do, so no need? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This example causes a type error:
You can obviously fix it like this:
However if you use
t
several times in the function it is a bit annoying to cast several times.This does not work:
This does but it shadows the variable:
How do you deal with things like this? In this case Teal could infer it automatically from the test, but in general it could be helpful to "persist" a cast.
I have this issue in real Lua code I am converting to Teal and the way I work around it for now is by with a sub-function like this:
Beta Was this translation helpful? Give feedback.
All reactions