local function bar(v: any): any
if not v is {string:any} or not v.field then
return
end
return v.field -- Error: cannot index key 'field' in any 'v' of type <any type>
end
local function baz(v: any): any
if not v is {string:any} then
return
end
if not v.field then
return
end
return v.field -- OK: v is {string:any}
end
The code of these 2 functions is equivalent.
But with a complex expression (ie. with a or), there is no narrowing type.
The code of these 2 functions is equivalent. But with a complex expression (ie. with a
or
), there is no narrowing type.