TypeScript Parameter Destructuring 语法 - 参数解构
生活随笔
收集整理的这篇文章主要介绍了
TypeScript Parameter Destructuring 语法 - 参数解构
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
您可以使用参数解构方便地将作为参数提供的对象解包到函数体中的一个或多个局部变量中。
function sum({ a, b, c }: { a: number; b: number; c: number }) {console.log(a + b + c); }let a = { a: 1, b: 2, c: 3 };sum(a);注意,这里第一行语句冒号后是类型定义。
我们可以简单改写下,提供代码可读性:
type ABC = { a: number; b: number; c: number };function sum({ a, b, c }: ABC) {console.log(a + b + c); } let a: ABC = { a: 1, b: 2, c: 3 };sum(a);更多Jerry的原创文章,尽在:“汪子熙”:
总结
以上是生活随笔为你收集整理的TypeScript Parameter Destructuring 语法 - 参数解构的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 一拳超人最强之男性感囚犯厉害吗 性感囚犯
- 下一篇: TypeScript 使用三个点号表示的