function print(): (number, string) {
return {1,'my'}
}
上面的代码显示错误,我希望我可以使用const {num, my} = print()
。指定返回类型的正确方法是什么?
最佳答案
尝试使用tuple 。它看起来像这样:
function print(): [number, string] {
return [1,'my']
}
const [num, my] = print();
请参阅 Typescript Playground 中的演示
关于javascript - typescript 返回解构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69664208/