react-tap-event-plugin: syntax error in Typescript when adding onTouchTap to div
Hello,
Using Typescript, in a .tsx file, after
import injectTapEventPlugin = require('react-tap-event-plugin')
injectTapEventPlugin()
with this JSX:
<div onTouchTap={ this.showFront }>
I get the syntax error:
error TS2339: Property 'onTouchTap' does not exist on type 'HTMLProps<HTMLDivElement>'.
in spite of having
interface HTMLDivElement {
onTouchTap: Function,
}
in the same code file, which should merge onTouchTap into the HTMLDivElement interface used by div in lib.d.ts
The intellisense is seeing onTouchStart
etc, but not onTouchTap
.
Is there something wrong, or am I doing something wrong?
Thanks,
- Henrik
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17
Hey guys, in the latest
@types/react
, use this solutionFYI to any newcomers to this, @blakeembrey responded to that ticket ^ and this solution works:
apparently by importing react first, you flip the file into module mode such that your module declaration augments the previous definition for react as opposed to over-writing it.
@ptitmouton FYI, I’ve opened https://github.com/Microsoft/TypeScript/issues/14325 to figure out what’s happening (I’m a curious guy 😃 ).
I am using it successfully with TS2. In the index.tsx rather than
import
useconst
…Then add a custom type definition for
require
. I created arequire.d.ts
file in my types dir withThat should do the trick.
Hm, I guess React typings have changed since? The snippet above doesn’t work for me with TS2 and react bindings from
@types/react
…This helped me out:
Not a great solution but you can place the props into an object and then destructure them into the element like:
This seems to dodge the type checker. I only have one instance of this in my code base at the moment but it won’t be fun if there are lots. Very happy to hear of a better solution. I can’t get the type extension described above to work. I suspect it is because the ‘react’ types have been re-written to a ‘@types’ approach and are now less extendable in some way? Though I’ve no idea what I’m talking about really.
@rlmckenney But doesn’t your tsc complain that
onTouchTap
is not a valid attribute when compiling.tsx
files?