Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

joonyoo181
Copy link
Contributor

This PR adds a section about user-defined type functions on page Typechecking after the "Type casts" section

@joonyoo181 joonyoo181 marked this pull request as ready for review August 9, 2024 01:52
@aatxe
Copy link
Contributor

aatxe commented Oct 21, 2024

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).

@joonyoo181
Copy link
Contributor Author

That makes total sense. Is there a projected date for when UDTF will be released in Beta?

@aatxe
Copy link
Contributor

aatxe commented Oct 22, 2024

Looking at fixing a few things up still before we can enable it, most notably type function exports and print. It's pretty close though, and some folks are already enabling the flags themselves to use it!

@@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## 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:
Copy link
Collaborator

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))
Copy link
Collaborator

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).
Copy link
Collaborator

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.

Copy link
Collaborator

@vegorov-rbx vegorov-rbx left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants