Luau keyof operator

As a Roblox developer, it is currently too hard to
convert table/type keys to a type. My idea is to add a keyof operator that would turn the keys into type.

Example:

--!strict

local a = { 
   a = 1
   b = 2
}

function GetValue(Key: keyof(typeof(a)) -- a | b)
   return a[Key]
end

If Roblox is able to address this issue, it would improve my development experience because at the moment I am writing my framework in the likeness of a knit, and in functions like GetService it would be good to use keyof

13 Likes

Has already been written up as a RFC and has been implemented into Luau, just waiting on Roblox now I believe: RFC: `keyof` and `rawkeyof` type operators by aatxe · Pull Request #16 · luau-lang/rfcs · GitHub

4 Likes

It has gone further.

7 Likes

What!! How??? Am I being deceived!?


Nope it is real, got merged a while ago.

@bitsplicer It being merged into Luau does not mean it’ll appear in Roblox Studio immediately or even around that time.

As I said when I linked that RFC in the first place, we usually have to wait for Roblox to implement it into Studio, and evidently, this claim holds up because it’s been about 2 months since it was merged and is just now being introduced.

1 Like

My point was never that it got added already, I was trying to show that since it is merged the process of being added has started.

Sorry for causing confusion.

1 Like

As a head’s up, even though the RFC has been merged and the feature has been implemented, it won’t be available within Studio for a while yet. The Luau team is working on a total rewrite of Luau’s type analyzer and keyof is only implemented in the new version.

I am told it will arrive “soon™” by team members on Discord, so make of that what you will.

9 Likes

Has a developer, I need this ! it’s been 4 months since we want it to be uploaded into Roblox Studio, what are you waiting for ! Strict developer will be happy

sorry for bump

1 Like

keyof is only available in the new type solver, which isn’t in a state that is ready for release. On Discord an engineer said that they hope to have the beta out soon (within a couple of weeks), but ultimately it will be ready when it is ready.

Hopefully it is actually soon this time

2 Likes

Does NodeOf will be created one day too ? Is there information in the Roblox OSS Community Server ?

Thanks for responding !

What is the suggested use for nodeof? There’s a variety of type functions like keyof in the new solver, but it’s not clear if what you want is already added.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.