将数组参数直接解压为参数?
Unpack array argument directly to parameters?
我知道我能做到:
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
}
好的,我想通了,不妨 post 作为答案。这有效:
function ([boolValue, stringValue]: [boolean, string]) {
// make use of boolValue and stringValue
}
我知道我能做到:
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
}
好的,我想通了,不妨 post 作为答案。这有效:
function ([boolValue, stringValue]: [boolean, string]) {
// make use of boolValue and stringValue
}