Better autocomplete!

image

I don’t understand why “Humanoid” is highlighted, but I get no autocomplete.

As a stopgap, give me “Humanoid” class autocompletes any time I have a variable named “Humanoid”. It would hit 80% of my usecases.

15 Likes

You are not getting autocomplete because Luau cannot infer that char.Humanoid is a humanoid, but if you do (char.Humanoid :: Humanoid): you should get better autocomplete after that last :

Or, if you don’t want to do that, declare char's type as Model & { Humanoid: Humanoid }

The script editor has received improvements w.r.t autocomplete, just seems like a lack of type annotations/assertions on your end.

Yours, maybe, and it still doesn’t hit 100%. I wouldn’t want Roblox to make assumptions about code based on variable names because not everyone is under the same assumptions.

13 Likes

I think it’s pretty reasonable to infer types when variables are named after the Roblox className. In the worse case, I sometimes get bad autocomplete results, but at the same time I often would get what I want.

I haven’t ventured into the world of Luau typing. In the post you reference, its a beta feature. Can I ship Luau code to production today?

2 Likes

local numberValue (the raw type or the NumberValue object?)

The advertised editor features are in beta. Luau itself has been out of beta for a while now, so the syntax is usable in production code, yes.

3 Likes

With no convenient workaround (apart from renaming) for users where this does matter, and Roblox could introduce types that match your old variable names and subsequently complicate auto-complete in your old code. It’s more sane to just properly type your code instead.

2 Likes

This is because Luau doesn’t know Humanoid’s type without it being specified.
As @sjr04 mentioned, this is currently the best solution

In future, we may be able to work with Luau team and figure out a better way to adjust the return value of ‘char’ from ‘any’, to ‘something that might be like humanoid’ . But it’s not available right now.

4 Likes