Playground example
Given some TypeScript code that calls toUpperCase on the property of an interface:
interface MyData {
name: string | undefined
}
const myData = <MyData> {
name : undefined
}
myData.name?.toUpperCase()
This produces Lua that fails with an error: attempt to call method 'toUpperCase' (a nil value)
myData = {name = nil}
local ____myData_name_toUpperCase_result_0 = myData.name
if ____myData_name_toUpperCase_result_0 ~= nil then
____myData_name_toUpperCase_result_0 = ____myData_name_toUpperCase_result_0:toUpperCase()
end
Extracting the property to a new value also produces invalid code.
const name : string | undefined = myData.name
name?.toUpperCase()
name = myData.name
local ____name_toUpperCase_result_2 = name
if ____name_toUpperCase_result_2 ~= nil then
____name_toUpperCase_result_2 = ____name_toUpperCase_result_2:toUpperCase()
end
But otherwise, it works
const newName: string | undefined = "blah blah blah"
newName?.toUpperCase()
-- correct
newName = "blah blah blah"
local ____newName_toUpperCase_result_4 = newName
if ____newName_toUpperCase_result_4 ~= nil then
____newName_toUpperCase_result_4 = string.upper(____newName_toUpperCase_result_4)
end
Playground example
Given some TypeScript code that calls
toUpperCaseon the property of an interface:This produces Lua that fails with an error:
attempt to call method 'toUpperCase' (a nil value)Extracting the property to a new value also produces invalid code.
But otherwise, it works