Weird luau type linting error

Am I doing something wrong here or is it just a bug or something…?

image

I have never seen that (:Loop()) before, are you sure it exists?

No, I’m defining that function not calling it…

I’ve just tried this (running the code) out of curiosity; since I have never seen:

local AI: {[string]: any}

For me it ran without error. Perhaps it is a possible bug.

The linter is probably mistaking the AI variable as a string and not a table. Try removing the type check thing you have and see if it still does it.

the compiler can compile it without issue, the problem lies within the linter spitting out errors that either i don’t understand or are just plain wrong

it gets identified as a table but no matter how i define the table i cannot declare a new member like this;

function t:method()

end

i have tried defining the table as {[any]: any} and defining the function type specifier as () which results in a similar warning

This is not a bug; Luau has introduced the concept of sealed tables. Once you define a table with one or more expression(s) or the table’s type is determined by a type annotation, the table becomes “locked down” and no more properties can be added.

Here’s a way to fix it:

type AI = {
	Loop: (AI) -> nil;
	[string]: any;
}

local ai: AI = {
	Target = nil;
	Status = "Inactive";
	
	Loop = function(self: AI)
		if not self.Target and self.Status == "Searching" then
			
		end
	end;
}

Just to note: You really shouldn’t be using colon syntax for calling functions in tables if you’re not dealing with OOP. AI is a singleton, therefore you wouldn’t need to use colon syntax and self. Doing this may have a bad habit be developed and often times, your code doesn’t work because you defined the function with colon, but called it with a dot (or vise versa)

type AI = {
	Loop: () -> nil;
	[string]: any;
}

local ai: AI = {
	Target = nil;
	Status = "Inactive";
	
	Loop = function()
		if not self.Target and self.Status == "Searching" then
            
        end
	end;
}
3 Likes