Brampage
Brampage

Reputation: 6964

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.

Upvotes: 13

Views: 10160

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 249486

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

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

Upvotes: 26

Related Questions