TypeScript:如何设置解构对象的类型? [英] TypeScript: How to set type of destructured object?

查看:71
本文介绍了TypeScript:如何设置解构对象的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

例如参数有如下类型 { component: any;元素:元素引用;},其中我只想要元素:

For example, the parameter has the following type { component: any; element: ElementRef; }, of which I only want the element:

onTextBoxInit({ element }) { }

问题:如何设置这个解构元素的类型?

Question: How can I set the type of this destructured element?

尝试过

我想到了这样的事情:onTextBoxInit({ element: ElementRef }) { },但是这是行不通的.

I thought of something like this: onTextBoxInit({ element: ElementRef }) { }, however this is not working.

推荐答案

需要在解构表达式后指定参数的类型

You need to specify the type of the argument after the destructuring expression

 onTextBoxInit({ element }: {element: ElementRef }){} 

这篇关于TypeScript:如何设置解构对象的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆