Shorthand custom type checking

I’ve not worked with type checking very often. I defined a custom table type and found that x and y or z doesn’t seem to be adequate nil checking and get Value of type options? could be nil which is just a warning, but it’s rather annoying as it’s shorthand for this:

if x ~= nil and x.y~= nil then
	--...
else
	--...
end

Here’s what I see in studio (I’ve written the shorthand version that has a warning and the long version that has no warnings, yet they accomplish the same thing)

I even tried explicitly checking nil:

Metrics.Version = additionalOptions ~= nil and additionalOptions.version ~= nil and additionalOptions.version or "1.0.0"

but I have the same issue here too.

And as you can see they get the same results:

Is there any way I could type check with shorthand or is that just not implemented?

How are you defining additionalOptions? Are you ever making a type for it or assigning a type to it? Also what’s the warn?

I actually figured out the problem. I had a ? where it wasn’t supposed to be. When defining my method I accidentally put a question mark in the parameters, which was unnecessary and caused this error.

So if anyone comes across this in the future is having the same issue, that might be why

1 Like