3

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?

Aaron Beall
  • 49,769
  • 26
  • 85
  • 103

2 Answers2

4

@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.

Courtney Christensen
  • 9,165
  • 5
  • 47
  • 56
1

Is the FastClick.d.ts wrong

Yes. Definitely Typed is best effort (like most documentation efforts disconnected from source) and wrong in this case.

basarat
  • 261,912
  • 58
  • 460
  • 511