代码之家  ›  专栏  ›  技术社区  ›  Dave Cousineau

将数组参数直接解包为参数?

  •  12
  • Dave Cousineau  · 技术社区  · 8 年前

    我知道我可以做到这一点:

    function (value: [boolean, string]) {
       const [boolValue, stringValue] = value;
    
       // make use of boolValue and stringValue
    }
    

    // doesn't work
    function ([boolValue: boolean, stringValue: string]) {
       // make use of boolValue and stringValue
    }
    
    1 回复  |  直到 8 年前
        1
  •  18
  •   Dave Cousineau    8 年前

    好吧,我想出来了,不妨把答案贴出来。这是有效的:

    function ([boolValue, stringValue]: [boolean, string]) {
       // make use of boolValue and stringValue
    }