Skip to content

setTimeout or setInterval type issue when using --watch #348

Closed
@mrkmg

Description

@mrkmg

Not sure if this is a bug in ts-loader, but I figured I would start here.

Package Versions
@types/node: 6.0.46
ts-loader: 0.9.5
typescript: 2.0.6
webpack: 1.13.3

As you can see, I am using @types/node for NodeJS type definitions.

The issue I am having is with setTimeout and setInterval. In @types/node, the "type" of the number that is returned from setTimeout or setInterval is "NodeJS.Timer". The following is valid and builds perfectly when run with just webpack.

let t: NodeJS.Timer;
t = setTimeout(() => console.log("test"), 1000);

The problem is when I run webpack --watch. On the initial build, everything is fine. Once I change the file which triggers a re-build, I get the following error:

ERROR in ./test.ts
(4,1): error TS2322: Type 'number' is not assignable to type 'Timer'.

It appears to be that on rebuilds, a different type definition is being used, one which defines the return of setInterval and setTimeout to be <number> instead of <NodeJS.Timer>. Obviously I can work around this, but seeing as these are standard functions in node and @types/node is a widely used type definition of the standard node library, it would probably be best to resolve this issue.

I have created a very minimal example to demonstrate the problem.

How to Reproduce

  1. Clone https://github.com/mrkmg/webpack-ts-loader-timer-error-example
  2. Run npm install or yarn install
  3. Run webpack --watch
  4. Change the file test.ts. (I just added a newline and hit save)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions