Right now luau typechecking doesn’t allow possible nil assignment on dictionaries
local map = {} :: {[Instance]: Instance}
function set(key: Instance, value: Instance?)
map[key] = value
end
map[key] = value
→ Type 'Instance?' could not be converted into 'Instance'
This behavior is particularly unintuitive because luau actually does support nil assignment as long as it’s explicitly refined to nil. For example, the following code has no warning:
local map = {} :: {[Instance]: Instance}
function set(key: Instance, value: Instance?)
if value then
map[key] = value
else
map[key] = value
end
end
So please allow assignment to a map if the value may be either the correct type of nil.