You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are many libraries in Lua that return something on success and nil + something on error. I am wondering about the best way to support that pattern.
One such example is http.request in LuaSocket. In teal-types it is typed as returning string, integer, {string:string}, string, but in practice it returns this ornil, string.
We could write string | nil, integer | string, {string:string}, string but what I think would be best is something like (string, integer, {string:string}, string) | (nil, string) (which does not exist)..
How do you deal with this in your Teal codebases?
Note: this question came from playing with Redbean which has functions defined like this in its documentation:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There are many libraries in Lua that return something on success and
nil + somethingon error. I am wondering about the best way to support that pattern.One such example is
http.requestin LuaSocket. In teal-types it is typed as returningstring, integer, {string:string}, string, but in practice it returns this ornil, string.We could write
string | nil, integer | string, {string:string}, stringbut what I think would be best is something like(string, integer, {string:string}, string) | (nil, string)(which does not exist)..How do you deal with this in your Teal codebases?
Note: this question came from playing with Redbean which has functions defined like this in its documentation:
Beta Was this translation helpful? Give feedback.
All reactions