-
Notifications
You must be signed in to change notification settings - Fork 66
RFC: Function Parameter Names in User-Defined Type Functions #137
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't names be an array of strings?
Maybe? I was going for consistency with the API for tables (I'd prefer if it just used strings, though) |
|
Array of strings might not work. |
Right. That's why I think it should be more like an unordered map. But should we actually use |
|
From what I can tell, in the Luau source code, argument names in function types look like this struct FunctionType
{
/* snip */
std::vector<std::optional<FunctionArgument>> argNames;
/* snip */
}To me, this suggests we should go with a type that looks something like one of the following: -- I'm using [number] here because the table isn't necessarily contiguous,
-- but it could also be written as {string?}?
type ArgumentNames = { [number]: string? }?or -- The types should be string singletons
type ArgumentNamesType = { [number]: type? }?Right now I'm wondering if we could get rid of the optional values in the table to make it a nice contiguous array. Perhaps a zero-length string (or string singleton) could represent missing parameter names instead of I'm just not sure if it's worth it. |
|
@deviaze suggested this approach, which I think is a much nicer solution, but it would unfortunately break existing code. If that's acceptable, since user-defined type functions are relatively new, I think this would be a much better option: type Parameters = {
{ name: string?, type: type }
} |
Going to nit and say the field for the type shouldn't be named |
But it's also the type of the parameter, right? I guess it makes sense to call it value in the type world, but I just find it weird to read it as "the type of the value of the parameter" instead of just "the type of the parameter". I'm fine with either to be honest. I'm going to be updating the RFC to use this approach since there hasn't been any reviews yet, but if breaking code is unacceptable we can always just revert it. |
Rendered
This RFC proposes a method to add names to function parameters in user-defined type functions.