I have a script that gets a team by its brickcolor.
local function GetTeamByBrickColor(brickcolor: BrickColor)
for i, team in pairs(Teams:GetTeams()) :: {Team} do
if team.TeamColor == brickcolor then
return team
end
end
error(`No team with brickcolor {brickcolor.Name}`)
end
When run, with the type annotation {Team}, I get the error:
Extra info:
I’m using the run test (so only server, no clients).
How to repo:
Create an empty place.
Create two server scripts.
In one server script, paste in this code:
local function GetTeamByBrickColor(brickcolor: BrickColor)
for i, team in pairs(Teams:GetTeams()) :: {Team} do
if team.TeamColor == brickcolor then
return team
end
end
error(`No team with brickcolor {brickcolor.Name}`)
end
In the other script,
local function GetTeamByBrickColor(brickcolor: BrickColor)
for i, team in pairs(Teams:GetTeams()) do
if team.TeamColor == brickcolor then
return team
end
end
error(`No team with brickcolor {brickcolor.Name}`)
end
Select the Run option in testing, then run.
Expected behavior
I expect annotations to not affect how a script functions.
This is by design, asserting a type of the expression value discards all extra values, just like (pairs(Teams::GetTeams())) will do.
This is because you are saying that the expression has a type of a single value, not a type pack of values.
In addition–your type is in the wrong place. pairs(Teams:GetTeams()) :: { Team } typecasts the result of pairs.
What you want is pairs(Teams:GetTeams() :: { Team }), or our recommendation: ditching pairs altogether and going with for i, team in Teams:GetTeams() :: { Team } do