Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript: How to set type of destructured object?

Problem

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?

Tried

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

like image 337
Brampage Avatar asked Jul 11 '18 08:07

Brampage


1 Answers

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

 onTextBoxInit({ element }: {element: ElementRef }){} 
like image 196
Titian Cernicova-Dragomir Avatar answered Sep 22 '22 15:09

Titian Cernicova-Dragomir