react jsx - syntax error in Typescript when adding onTouchTap to div -


using typescript, in .tsx file, after

import injecttapeventplugin = require('react-tap-event-plugin') injecttapeventplugin() 

with jsx:

<div ontouchtap={ this.showfront }> 

i syntax error:

error ts2339: property 'ontouchtap' not exist on type 'htmlprops<htmldivelement>'. 

in spite of having

interface htmldivelement {      ontouchtap: function,  } 

in same code file, should merge ontouchtap htmldivelement interface used div in lib.d.ts

the intellisense seeing ontouchstart etc, not ontouchtap.

is there wrong, or doing wrong?

thanks,

  • henrik

in same code file, should merge ontouchtap htmldivelement interface used div in lib.d.ts

no. because file module have root level import (import injecttapeventplugin). means disconnected global namespace

also interface want extend not htmldivelement dom attributes defined in react.d.ts.

fix

you need create vendor.d.ts , put inside:

declare module __react{     interface domattributes {         ontouchtap?: function,     } } 

more : https://basarat.gitbooks.io/typescript/content/docs/project/modules.html


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -