-
-
Notifications
You must be signed in to change notification settings - Fork 184
Closed
Labels
Description
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()
endExtracting 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()
endBut 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)
endReactions are currently unavailable