Need help doing type checking for all values in a dictionary

Here is my code:

--!strict
local dict: {[string]: boolean} = {
	code1 = true,
	code2 = false
}

When I change the value of key code1 from true to 123, Studio’s typechecker warns me that this is invalid. So far so good, this is expected, since I explicitly said that dict has a type {[string]: boolean}, and putting a number there would be a silly mistake that it should catch.

Problem:
However, I don’t get a warning if I make this same mistake for the next line, and change code2’s value from false to 123. For some reason, the Studio type checker is ok with this and does NOT put a warning, even though I do want it to tell me that I’m making a mistake.

It seems like it only validates the type for the first key value pair in the dictionary, but not for subsequent pairs.

How should I properly ensure that ALL values stored in this dict are booleans? Did I just made a syntactical mistake? Or am I trying to do something that I shouldn’t even be trying to do?

Works fine for me as-is. Maybe restart Studio? :person_shrugging:
Maybe just try retyping ‘boolean’ and see if that causes it to rethink what it’s doing. You running the Beta type solver?

So, just to confirm - you took the example above and changed the second key-value pair to be code2 = 123 and it DID successfully warn you?

I changed the value of first pair to 123 and was warned and changed back to true. I may have used 111 when I changed the second, but otherwise it warned me. After that I did a number of change combinations like leaving both as numbers, setting both to true at first and such and was warned every time. [yes. copied/pasted your code]
Edit: rechecked, and yes, 123 on second key-value pair warns me. I’m not using the Beta version of the lua checker.

ah… it fails if I run the beta checker

1 Like

Ah, thanks, you’re a lifesaver, I was so lost. Yes, I’m using the Beta checker. Let me try turning off the beta checker and seeing if it warns me successfully.

Edit: confirmed, it fails to warn me when using the Beta type solver , but it does warn me once I turn off this Beta feature.

1 Like