Why didn't Luau's type checking catch this typo?

I was just pulling my hair out over this typo. In Checkpoint's constructor, spawnlocation was misspelled as spawnloacation.

type Checkpoint = {
    spawnlocation: SpawnLocation,
    conn: RBXScriptConnection,
    level: number,
    gui: SurfaceGui,
}

local Players = game:GetService("Players")

local Checkpoint = {}
Checkpoint._index = Checkpoint

function Checkpoint.new(spawnlocation: SpawnLocation): Checkpoint
    local level = spawnlocation:FindFirstChild("Level")
    assert(level and level:IsA("IntValue"))

    local newcheckpoint: Checkpoint = {
        spawnloacation = spawnlocation,
        --[[
             ...
        --]]
    }
    
    --[[
         ...
    --]]

    setmetatable(newcheckpoint, Checkpoint)

    return newcheckpoint
end

However, this typo doesn’t exist in the type definition at the top of the script. For whatever reason, Luau didn’t complain about this typo, despite me setting the return type of a constructor to Checkpoint. Instead, I had to find this out the normal way by freaking out and putting print statements everywhere.

Could be a variety of things but I’m guessing you don’t have --!strict defined at the top of your script.

That seems to have helped, but it only produces a linter error in Studio’s script editor, which means if you use a different editor (I was using VSCode w/ Rojo at the time), you won’t get any runtime warnings.

I honestly don’t know I never use strict type checking outside of Roblox it’s not developed enough to be reliable.

The lua debugger can be an incredibly helpful alternative to this :slight_smile:

Also, I’m not sure roblox officially supports any third party editors. If there’s a bug with whatever extension you’re using you should take it up with the extension’s authors.

I also used breakpoints, but I found my typo by reading the printed version of one of my Checkpoint objects. I also sorta expected type issues to be warnings in the output console when starting my game too :man_shrugging:

1 Like