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 ref types #12

Open
fewkz opened this issue Apr 26, 2023 · 2 comments · May be fixed by #15
Open

Add ref types #12

fewkz opened this issue Apr 26, 2023 · 2 comments · May be fixed by #15
Labels
enhancement New feature or request not sure

Comments

@fewkz
Copy link
Owner

fewkz commented Apr 26, 2023

Make a froact.createRef() function that returns { current: Instance }
with the code:

type Ref = { current: Instance }
local function createRef(): Ref
    return froact.Roact.createRef()
end

As it turns out, you can do .current on Roact refs. We can type the ref property on Roblox instance components as { current: Instance } so that you'll never fuck up the type of refs ever!

We get the beautiful, absolutely amazing extravagance of branch-based luau type inference! This is absolutely invaluable.
image

oh, and while we're add it, add froact.useRef(hooks), instead of doing hooks.useMemo(froact.createRef(), {})

@fewkz fewkz added enhancement New feature or request not sure labels Apr 26, 2023
@fewkz
Copy link
Owner Author

fewkz commented Apr 26, 2023

not sure about this, actually, refs being typed as any is nice, because you can usually assume the value of a ref correctly, there's mostly not going to be a case where you really want to assert whatever it's value is. Getting autocomplete for .current is nice, but wow is it nit-picking.

@fewkz
Copy link
Owner Author

fewkz commented Apr 27, 2023

An implementation of this is available in the https://github.com/fewkz/froact/tree/ref-binding branch

@fewkz fewkz linked a pull request May 1, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request not sure
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant