Parcel: module.hot typescript error

Created on 24 Mar 2018  路  4Comments  路  Source: parcel-bundler/parcel

Feature request

馃 Expected Behavior

Typescript should be made aware of the module.hot property.

馃槸 Current Behavior

There is a ts lint error when trying to access module.hot.

Property 'hot' does not exist on type 'NodeModule'.

module is defined out of the box as a NodeModule in ~/Library/Caches/typescript/2.7/node_modules/@types/node/index.d.ts which is probably installed by vscode.

馃拋 Possible Solution

Installing @types/webpack-env fixes the ts lint error.

It does this by extending the NodeModule type.

interface NodeModule extends __WebpackModuleApi.Module {}

Perhaps there should be a @types/parcel-env module.

馃敠 Context

Decided to try out parcel as I have previously been using webpack a lot. I am happy with it but parcel looked very interesting, and simpler in many ways.

I'm also trying Preact, and immediately fell into the hot module issue documented here https://github.com/parcel-bundler/parcel/issues/261.

I am using the jsdoc functionality to use typescript in vscode to validate my js and jsx files.

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.6.2 |
| Node | 8.10.0 |
| Yarn | 1.5.1 |
| Operating System | Mac OSX High Sierra 10.13.3 |
| VSCode | 1.21.1 |

Feature TypeScript

Most helpful comment

All 4 comments

declare var module : {
  hot : {
    accept(path?:string, callback?:() => void): void;
  };
};

Thankyou @FDiskas, or since I'm using js with jsdoc and have d.ts files in a typings folder, maybe this

declare global {
    interface NodeModule {
        hot : {
            accept(path?: string, callback?: () => void): void
        }
    }
}

export { }

This is what I'm doing with window, I'm not sure if it's the perfect way of doing this.

This should be documented

Was this page helpful?
0 / 5 - 0 ratings