Skip to content

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!

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 too incomplete and outdated.

@vegorov-rbx
Copy link
Collaborator

Closing as the PR seems abandoned.

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.

None yet

3 participants