And I got no warning from the Strict type checker. I assigned a Folder type variable to nil. No warnings. No blue line under the code.
Here is the whole function definition:
--!strict
Shared.GetFoldersLinkSingleton = function(parent: Folder | Workspace, ...: string): Folder?
if typeof(parent) ~= "Instance" then
return nil
end
if not parent:IsA("Folder") and not parent:IsA("Workspace") then
return nil
end
local arguments = {...}
if #arguments <= 0 then
return nil
end
for _, argument in ipairs(arguments) do
if typeof(argument) ~= "string" then
return nil
end
end
local currentParent = parent
for _, argument in ipairs(arguments) do
local children = currentParent:GetChildren()
local normalizedChild: Folder = nil
for _, child in ipairs(children) do
if child.Name ~= argument then
continue
end
if not child:IsA("Folder") then
continue
end
normalizedChild = child
break
end
if not normalizedChild then
local newNormalizedChild = Instance.new("Folder")
newNormalizedChild.Name = argument
newNormalizedChild.Parent = currentParent
normalizedChild = newNormalizedChild
end
currentParent = normalizedChild
end
return currentParent :: Folder
end
This is not a bug. Luau strict allows nil assignments to typed variables.
local normalizedChild: Folder? = nil
local normalizedChild = nil
Both are valid, and neither will produce a strict-mode error.
I don’t see why people put themselves through the hassle of strict unless you’re actually using something to slam into something as the type of variable only and you’re not checking for that. Like you’re actually relying on type enforcement. Most of the time there is no need for this.
Strict mode isn’t providing any real benefit here. You’re not actively using it to enforce or check types. It’s not “better than”.. at its core, it’s just a mode for enforcing types.
The question mark should allow nil values to get assingned, and the absence of the ? should not. You used ?, so Luau type checker should not give a warning there, but I didn’t used ? in my example and I still didn’t got a warning
I enabled the beta feature, it worked for this case, but made other wierd errors in the code base that have no sense. I will disable it and ignore all the wierd errors or absence of errors until the type checker becomes better.