Filter return type based on input arguments. #2174
Replies: 1 comment 1 reply
-
We can get somewhere close to this by using overloads like so: ![]() ![]() However, there are some issues here. It seems when figuring out the return type, the language-server just returns the union of all return-types with overloads (or the original function) with the same amount of params. It doesn't at all check the type of params when determining what the return type is. For example: ![]() Considering the type here is nil, and this only matches the base function not the overload, I would expect the return type to match the base function and not also the overload function. cc: @sumneko Would it be possible to have the language-server look at the function arguments type and not just the number of arguments when determing what function something belongs to? (There is also an associated issue here, where if subsequent arguments are of type any, it will also match, even if the number of arguments are different. ex: |
Beta Was this translation helpful? Give feedback.
-
A common behavior in a code-base I am working on is for functions to generally error on nil, but to allow custom handling of nil if the function user passes in an argument. Ex:
Is there currently a way to modify the return type based on arguments (using generics or something) so that the return type in the example would be
string
ifpassthrough
wasfalse or nil
butstring | nil
ifpassthrough
wastrue
?Beta Was this translation helpful? Give feedback.
All reactions