sindresorhus/delay

Mistaken in type definition? TypeScript compiler refuses to allow calling default import

Closed this issue · 3 comments

Not sure how to express what is happening exactly, and perhaps it is related to (#32), but tsc won't compile the following code:

// code.ts
import * as delay from 'delay';
delay(100);
code.ts:3:1 - error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'typeof import("/home/user/my-project/node_modules/delay/index")' has no compatible call signatures.

3 delay(100);
  ~~~~~~~~~~


Found 1 error.

However, it seems that I can "fool" tsc into compiling it anyway by doing this:

import * as delayDefault from 'delay';
const delay: any = delayDefault;
delay(100);

I am using node 10.15.1, delay 4.1.0, tsc 3.3.1, and Linux (4.9.0-8-amd64)

import delay from 'delay'

Ah, thanks for correcting. I still get my import syntax mixed up sometimes, I guess.

@sindresorhus - When I try and use the import syntax shown I get an error from rollup

(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
delay (imported by src\objects\npc.ts)
(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
delay (guessing 'delay')

I noticed the comment // TODO: Remove this for the next major release. in index.d.ts so is this expected to change? What's the correct way of referring to this from Typescript. Any suggestions on dealing with the rollup error?