Array destructuring in parameters list, with TypeScript

前端 未结 1 462
萌比男神i
萌比男神i 2020-12-17 18:19

Using TypeScript, I am trying to figure out how to do array destructuring in the arguments list.

We can use object destructuring like so:

let foo = f         


        
1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 18:41

    An array of fixed length and types is also called a tuple in TS. We can destructure a tuple argument like:

    let bar = function ([desc, opts, fn]: [string, {}, Function]) {
    
    
    }
    
    bar([
        'yes',
        {},
        function () { }
    ]);
    

    0 讨论(0)
提交回复
热议问题