What is the use of lua's "var: type" assignment method?

I recently was reminded of using var: type to declare variables.

I asked my colleague who’s a bit more vetted in lua and its various workings than myself, and he came up with the following:

"It's so you can't set a var to a different type in the syntax checker"

However, when I tried to preview this suggested behaviour in studio’s script editor, it didn’t give me any flak for setting a declared as a: number to true.

Anyone got any ideas on its actual use case along with some (dis)advantages of using it?

This is a part of Roblox’s type checking shenanigans. I don’t really like it mostly because it’s still in it’s infancy but you can enable it by adding
--!strict
to the top of your script

Oh, wow.

That was surprisingly satisfying to discover.

Thanks for your insight! I really really doubt I shall ever use this, however it’s nice to know what options I have available to me.

1 Like