jquery - Does TypeScript version 1.7.6 support dts lib for touchevents? -


i found following link: does typescript support touchevent?

it deals issue having. according post @ top of article, states typescript 1.5.3 added declarations html touch events lib.d.ts.

does typescript version 1.7.6 support these touch events? getting error in visual studio 2015 states: property 'changedtouches' not exist on type 'event'.

what lib.d.ts required work. have tried using nuget download latest jquery.typescript.definitelytyped version="2.8.8", not appear work.

any suggestions?

update verified jquery d.ts file nuget same 1 on https://github.com/definitelytyped/definitelytyped.

code snippet

$('#previewevent').on('mousedown touchstart', function(e) {   var original = e.originalevent;   if (original.changedtouches && checkmobile.istouch_p) {       const touchobj = original.changedtouches[0];       swipedir = 'none';       distx = 0;       disty = 0;       startx = touchobj.pagex;       starty = touchobj.pagey;       // record time when finger first makes contact surface       starttime = new date().gettime();       return !0;  } else if (!checkmobile.istouch_p) {       return !0;   }   return !0;  });

update thought lib.d.ts referred jquery. wrong, 1 of libraries installed typescript.

i have updated library, still have same error. lib.d.ts file seem have touch definitions, step in right direction.

the issue appears incompatibility between jquery basejqueryeventobject interface , typescript touchevent interface. not yet sure how resolve issue, can eliminate error declaring var original: = e.originalevent, masks incompatibility.

any ideas on how solve right way? guessing take third d.ts file iron out interfaces.

thanks...

in handler function e of type jqueryeventobject.

originalevent comes basejqueryeventobject , it's of type event. event lib.d.ts. clear far.

because event base interface lot of derived event types (like gamepadevent, mutationevent , on) contains fields shared data across event types. that's why can't access changedtouches, because far typescript compiler concerned it's not touchevent.

i go solving feature introduced in typescript 1.4 called type guards.

a common pattern in javascript use typeof or instanceof examine type of expression @ runtime. typescript understands these conditions , change type inference accordingly when used in if block.

because specifying same handler mousedown , touchstart events, e.originalevent can mouseevent or touchevent.

so have handle these 2 cases:

$("#previewevent").on("mousedown touchstart", function(e) {     var original = e.originalevent;     if(original instanceof touchevent) {         // handling touchstart event     } else if(original instanceof mouseevent) {         // handling mousedown event     } }); 

the thing is, quote says, proper autocompletion support in each branch of if statement.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -