Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3.2] .d.ts references dom Request/Response #1270

Closed
AviVahl opened this issue May 17, 2022 · 5 comments · Fixed by #1271
Closed

[5.3.2] .d.ts references dom Request/Response #1270

AviVahl opened this issue May 17, 2022 · 5 comments · Fixed by #1271

Comments

@AviVahl
Copy link
Contributor

AviVahl commented May 17, 2022

Bug report

new release changed the typings, and where it says Request/Response, it references global ones defined by dom.d.ts.

Actual Behavior

node_modules/webpack-dev-middleware/types/index.d.ts:168:21 - error TS2344: Type 'Request' does not satisfy the constraint 'IncomingMessage'.
  Type 'Request' is missing the following properties from type 'IncomingMessage': aborted, httpVersion, httpVersionMajor, httpVersionMinor, and 46 more.

168   headers?: Headers<Request, Response>;

Expected Behavior

It should pass type checking in strict typescript projects that don't specify skipLibCheck.

How Do We Reproduce?

mkdir dev-middleware-bug
cd dev-middleware-bug
npm init -y
npm i webpack webpack-dev-middleware typescript
npx tsc --init --skipLibCheck false
echo "import 'webpack-dev-middleware';" > a.ts
npx tsc --noEmit

Please paste the results of npx webpack-cli info here, and mention other relevant information

  System:
    OS: Linux 5.17 Fedora Linux 36 (Workstation Edition)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
    Memory: 56.48 GB / 62.43 GB
  Binaries:
    Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v16.15.0/bin/yarn
    npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
  Browsers:
    Chrome: 101.0.4951.64
    Firefox: 100.0
  Packages:
    html-webpack-plugin: ^5.5.0 => 5.5.0 
    webpack: ^5.72.1 => 5.72.1 
    webpack-dev-middleware: ^5.3.2 => 5.3.2 
@AviVahl
Copy link
Contributor Author

AviVahl commented May 17, 2022

@luoguoxiong
Copy link

I have the same problem~

@nuintun
Copy link
Contributor

nuintun commented May 18, 2022

+1

type API<
Request_1 extends import("http").IncomingMessage,
Response_1 extends ServerResponse
> = Middleware<Request, Response> & AdditionalMethods<Request, Response>;

Request_1 and Response_1 generic definition is unused.

@alexander-akait
Copy link
Member

@AviVahl Weird, we don't touch ts files, just update deps, maybe regression in ts?

@alexander-akait
Copy link
Member

alexander-akait commented May 18, 2022

Found ts regression, when you have:

/**
 * @template {IncomingMessage} Request
 * @template {ServerResponse} Response
 * @typedef {Object} Options
 * @property {{[key: string]: string}} [mimeTypes]
 * @property {boolean | ((targetPath: string) => boolean)} [writeToDisk]
 * @property {string} [methods]
 * @property {Headers<Request, Response>} [headers]
 * @property {NonNullable<Configuration["output"]>["publicPath"]} [publicPath]
 * @property {Configuration["stats"]} [stats]
 * @property {boolean} [serverSideRender]
 * @property {OutputFileSystem} [outputFileSystem]
 * @property {boolean | string} [index]
 */

ts 4.6 consider Request and Response as global classes in dom.lib.ts (as @AviVahl mention), not as local generics, very weird, let's downdgrade and fix types and report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants