Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using clipboardData in TypeScript

Tags:

typescript

I'm trying to access data from the clipboard in TS1.6 using the following:

$(container).bind("paste", (e) => {
    var data = e.originalEvent.clipboardData.getData('text');
});

But it just gives me the following build error:

Property 'clipboardData' does not exist on type 'JQueryEventObject'

If I remove the 2nd line and debug it in Chrome 46, I can get at the clipboard data just by calling

e.originalEvent.clipboardData.getData('text');

I can't see clipboardData in the JQueryEventObject interface in the latest version of jQuery.d.ts but the question is - should it be there or is there a different way of retrieving data from the clipboard that TS currently supports?

like image 443
CatBusStop Avatar asked Dec 03 '15 09:12

CatBusStop


1 Answers

Use ClipboardEvent type (e.g.)

private onPaste(event: ClipboardEvent) {
    const {clipboardData} = event;
    const pastedText = clipboardData.getData('text');
}
like image 94
Ekaterina Tokareva Avatar answered Oct 22 '22 16:10

Ekaterina Tokareva