Remove asserts the types already cover

The nil check burn down added guards which turned out redundant once
the surrounding annotations landed. `_has_handlers` is set to true when
the first handler registers, so it is a boolean rather than the literal
false it was inferred as.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-07 15:31:48 +00:00
co-authored by Claude Opus 5
parent f907007d14
commit 619ed4b39f
19 changed files with 68 additions and 55 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ local function get_server_id(server)
elseif status == "Offline" then
return false, { "exp-commands_connect.offline", server_details.name }
end
return true, server_id
return true, server_id --[[@as string]]
elseif server_count_before > 0 then
return false, { "exp-commands_connect.wrong-version", concat(server_names_before, ", ") }
else
+4 -4
View File
@@ -43,11 +43,11 @@ Commands.new("create-report", { "exp-commands_reports.description-create" })
if Reports.report_player(other_player, player.name, reason) then
local user_message = { "exp-commands_reports.response", other_player_name, reason }
local admin_message = { "exp-commands_reports.response-admin", other_player_name, player_name, reason }
for _, player in ipairs(game.connected_players) do
if player.admin then
player.print(admin_message)
for _, connected_player in ipairs(game.connected_players) do
if connected_player.admin then
connected_player.print(admin_message)
else
player.print(user_message)
connected_player.print(user_message)
end
end
else
+1 -1
View File
@@ -91,7 +91,7 @@ local function sort_results(results, func)
end
end
return sorted
return sorted --[[@as SearchResult[] ]]
end
local display_players_time_format = ExpUtil.format_time_factory_locale{ format = "short", hours = true, minutes = true }
@@ -32,7 +32,7 @@ end
--- Get the player name from an event
--- @param event { player_index: uint, by_player_name: string? }
--- @return string, string
--- @return string, string?
local function get_player_name(event)
local player = game.players[event.player_index]
return player.name, event.by_player_name
+2 -2
View File
@@ -102,11 +102,11 @@ Elements.reason_confirm = Gui.define("player_list/reason_confirm")
local action_name = Elements.container.get_selected_action(player)
local button_data = action_name and config.buttons[action_name]
if button_data and button_data.reason_callback then
local reason = assert(assert(element.parent).entry).text --[[@as string?]]
local reason = assert(element.parent).entry.text --[[@as string?]]
if reason == nil or not reason:find("%S") then reason = "no reason given" end
button_data.reason_callback(player, reason)
end
assert(assert(element.parent).entry).text = ""
assert(element.parent).entry.text = ""
Elements.container.set_selected_player(player, nil)
Elements.player_table.refresh_player(player)
end) --[[@as any]]
+1 -1
View File
@@ -43,7 +43,7 @@ local function new_quick_action(command, on_click)
:style{
width = 160,
}
:on_click(on_click or function(def, player, element, event)
:on_click(on_click or function(_def, player, _element, _event)
command(player)
end)
@@ -270,10 +270,9 @@ Elements.container = Gui.define("research_milestones/container")
local milestone_table = Elements.milestone_table(container)
Elements.clock_label(header)
local force = Gui.get_player(parent).force
local force = Gui.get_player(parent).force --[[@as LuaForce]]
def.data[force] = def.data[force] or {} -- used by start index and row data
local force = Gui.get_player(parent).force --[[@as LuaForce]]
local start_index = Elements.container.calculate_starting_research_index(force)
for research_index = start_index, start_index + display_size - 1 do
local row_data = Elements.milestone_table.calculate_row_data(force, research_index)
@@ -297,7 +296,7 @@ end
--- @param research_index number
--- @return number
function Elements.container.get_achieved_time(force, research_index)
return Elements.container.data[force][research_index]
return assert(Elements.container.data[force][research_index])
end
--- Calculate the starting research index for a force
@@ -109,7 +109,7 @@ function Elements.production_label.calculate_display_data(tooltip, value, cutoff
end
local suffix, caption = format_number(value)
display_data = display_data or {}
display_data = display_data or {} --[[@as Elements.production_label.display_data]]
display_data.caption = caption
display_data.suffix = suffix
display_data.tooltip = tooltip
@@ -221,7 +221,7 @@ function Elements.science_table.calculate_row_data(force, science_pack, row_data
end
-- Return the pack data
row_data = row_data or {}
row_data = row_data or {} --[[@as ExpGui_ScienceProduction.elements.science_table.row_data]]
row_data.visible = production.total.made > 0
row_data.science_pack = science_pack
row_data.icon_style = icon_style
+1 -1
View File
@@ -612,7 +612,7 @@ function Elements.confirm_task_button.parse(message)
-- Trim the spaces of the string
local trimmed = string.gsub(message, "^%s*(.-)%s*$", "%1")
local title, body = string.match(trimmed, "(.-)\n(.*)")
local parsed = { title = title, body = body }
local parsed = { title = title, body = body } --[[@as { title: string, body: string }]]
if not title then
-- If it doesn't match the pattern return the str as a title
parsed.title = trimmed