Skip to content

fix(v2): re-export express Response from the https provider - #1947

Open
kyungseopk1m wants to merge 1 commit into
firebase:masterfrom
kyungseopk1m:fix/export-express-response
Open

fix(v2): re-export express Response from the https provider#1947
kyungseopk1m wants to merge 1 commit into
firebase:masterfrom
kyungseopk1m:fix/export-express-response

Conversation

@kyungseopk1m

Copy link
Copy Markdown
Contributor

Description

onRequest handlers take an express.Response, but src/v2/providers/https.ts only re-exports Request. To annotate a handler parameter you have to add express as a direct dependency just to name the type, even though firebase-functions already depends on it.

v1 does not have this gap: src/v1/cloud-functions.ts re-exports both Request and Response, so functions.Response resolves today. This brings v2 in line.

Response is re-exported from express rather than aliased as export type Response = express.Response, because the express type is generic (Response<ResBody, Locals, StatusCode>) and an alias drops the type parameters, which makes https.Response<MyBody> fail with TS2315.

Fixes #1798.

Code sample

Before, this needs express installed and imported directly:

import { onRequest } from "firebase-functions/v2/https";
import type { Response } from "express";

export const fn = onRequest((req, res: Response<{ ok: boolean }>) => {
  res.json({ ok: true });
});

After:

import { onRequest, type Request, type Response } from "firebase-functions/v2/https";

export const fn = onRequest((req: Request, res: Response<{ ok: boolean }>) => {
  res.json({ ok: true });
});

Scenarios Tested

npm run build and npm run lint pass.

Checked the emitted surface rather than only the source: after building, a probe importing https from lib/v2/index and using https.Response<{ ok: boolean }>, bare https.Response, https.Request, and a full handler signature type checks with tsc --noEmit. The generic form is what fails on an alias, so it is the case that matters here.

Release notes

relnote: fix(v2): re-export the express Response type from firebase-functions/v2/https (#1798)

onRequest handlers are typed with express.Response, but only Request was
re-exported. Annotating a handler parameter meant adding express as a
direct dependency just to name the type.

v1 already re-exports Response from cloud-functions.ts. Do the same here
so both generations expose it.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request exports the Response type from express in src/v2/providers/https.ts. I have no feedback to provide.

@IzaakGough IzaakGough left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@shettyvarun268 shettyvarun268 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Not a blocker at all since its a small change, but we can have a small type assertion test to ensure that Response export does not regress in future refactors.

LGTM otherwise!

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 this pull request may close these issues.

Re-export express.Response

4 participants