-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add section about user-defined type functions #29
base: master
Are you sure you want to change the base?
Conversation
This will need some slight edits to match the final RFC, but I don't want to merge it in until we've at least enabled it in the New Type Solver Studio Beta (and we can mention that it's available in the Beta rather than just say not yet released). |
That makes total sense. Is there a projected date for when UDTF will be released in Beta? |
Looking at fixing a few things up still before we can enable it, most notably type function exports and |
@@ -618,6 +618,37 @@ local value = numericValue :: any -- ok, all expressions may be cast | |||
local flag = numericValue :: boolean -- not ok, invalid 'number' to 'boolean' conversion | |||
``` | |||
|
|||
## Type functions (yet to be released) |
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.
## Type functions (yet to be released) | |
## Type functions |
end | ||
``` | ||
|
||
To modify types within type functions, we can use the `type` userdata and its methods. Note that this userdata is *only* available in the context of type functions. An example of a type function is: |
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.
We now have types
library and type
userdata values separately.
end | ||
|
||
for k, v in tbl:getprops() do | ||
tbl:setprop(k, type.getunion(v, type.niltype)) |
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.
Doesn't match current RFC/implementation (types.getunion, types.singleton(nil))
|
||
In this example, the `partial` type function takes a table type and iterates through the properties and modifies them to be optional. | ||
|
||
This feature will be in beta and have several limitations. We are in the first iteration of this feature. For more details about the `type` userdata and the state of type functions, please read the RFC [here](https://rfcs.luau-lang.org/user-defined-type-functions.html). |
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.
Would be best to drop the beta.
Limitations are best mentioned (I would say missing generic type support is a big one that users are hitting fast).
Instead of referring to RFC, I would prefer the documentation on our website to document the feature directly, full API included.
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.
Current section is way to incomplete and outdated.
This PR adds a section about user-defined type functions on page Typechecking after the "Type casts" section