Skip to content

Default values in destructuring handle false incorrectly #529

@ark120202

Description

@ark120202

Input:

function test1(foo = true) {}
function test2({ foo = true }: { foo?: boolean }) {}
function test3([foo = true]: [boolean?]) {}

Current Result:

local function test1(self, foo)
    if foo == nil then
        foo = true
    end
end
local function test2(self, ____TS_bindingPattern0)
    local foo = ____TS_bindingPattern0.foo or true
end
local function test3(self, ____TS_bindingPattern0)
    local foo = ____TS_bindingPattern0[1] or true
end

Expected Result:

local function test1(self, foo)
    if foo == nil then
        foo = true
    end
end
local function test2(self, ____TS_bindingPattern0)
    local foo = ____TS_bindingPattern0.foo
    if foo == nil then
        foo = true
    end
end
local function test3(self, ____TS_bindingPattern0)
    local foo = ____TS_bindingPattern0[1]
    if foo == nil then
        foo = true
    end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions