I have been trying to use FastClick in my TypeScript project with FastClick.d.ts. My TSC configuration uses "module: commonjs" and I am bundling everything with Webpack. However, I am having trouble referencing FastClick properly.
When I try to import FastClick like this:
import {FastClick} from 'fastclick'
FastClick.attach(document.body);
There are no compile errors, but the transpiled code looks incorrect:
var fastclick_1 = require('fastclick');
fastclick_1.FastClick.attach(document.body)
This setup does not work as expected. It seems like fastclick_1
is actually the FastClick
function itself.
If I change the import to:
import * as FastClick from 'fastclick'
FastClick.attach(document.body)
I get a compile error that says
Error:(6, 49) TS2339: Property 'attach' does not exist on type 'typeof fastclick'
, but the emitted JavaScript works fine:
var FastClick = require('fastclick');
FastClick.attach(document.body);
So, how can I make sure both TSC and the emitted JS work correctly? Could it be an issue with the FastClick.d.ts file or am I importing the module incorrectly?