I'm using FastClick with FastClick.d.ts. TSC is using module: "commonjs" and I'm bundling with Webpack. I can't figure out how to reference FastClick.
How can I import FastClick into TypeScript? If I do this:
import {FastClick} from 'fastclick'
FastClick.attach(document.body);
I get no TSC compile errors, but the transpiled code looks like this:
var fastclick_1 = require('fastclick');
fastclick_1.FastClick.attach(document.body)
Which doesn't work. fastclick_1 appears to be the FastClick function itself.
If I do this:
import * as FastClick from 'fastclick'
FastClick.attach(document.body)
I get a compile error Error:(6, 49) TS2339: Property 'attach' does not exist on type 'typeof fastclick', but the emitted JS works:
var FastClick = require('fastclick');
FastClick.attach(document.body);
So how can I get TSC and the emitted JS to both work? Is the FastClick.d.ts wrong? Am I importing the module wrong?
@basarat never merged his pull request. Calling attach via bracket notation will prevent the TSC error and emit the proper JS.
import * as FastClick from 'fastclick';
FastClick['attach'](document.body);
It's not ideal, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With