Skip to content

fix(storage): give the compat fromTask an explicit return type - #3796

Open
armando-navarro wants to merge 1 commit into
angular:mainfrom
armando-navarro:a69-fromtask-return-type
Open

armando-navarro wants to merge 1 commit into
angular:mainfrom
armando-navarro:a69-fromtask-return-type

Conversation

@armando-navarro

Copy link
Copy Markdown
Collaborator

Fixes #3677

This gives the compat fromTask an explicit return type, so the published @angular/fire/compat/storage typings stop depending on how the typings bundler names an inferred Firebase type.

Changes

  • fromTask in src/compat/storage/observable/fromTask.ts declares Observable<UploadTaskSnapshot>. The type is unchanged: UploadTaskSnapshot is the compat alias for firebase.storage.UploadTaskSnapshot.
  • Removes a comment explaining a firebase import that add eslint #3421 removed in 2023.
  • Once this merges, it will be cherry-picked to 20.1.x, so a 20.1 patch release fixes @angular/build: TS2307: Cannot find module 'firebase/compat' #3677 for apps on the latest tag.

Why

Without a declared return type, the typings import whatever module path the bundler picks for the inferred type:

  • 20.0.1 and 20.1.0 import 'firebase/compat'. The firebase package's exports map has no ./compat entry, so apps using moduleResolution: "bundler" fail with TS2307: Cannot find module 'firebase/compat'. Angular's use-application-builder migration switches apps to that setting, which is how @angular/build: TS2307: Cannot find module 'firebase/compat' #3677 ran into it.
  • 21.0.0-rc.1 happens to import 'firebase/compat/app', which resolves, so it compiles.
  • ng-packagr 22.2, which the Angular 22 upgrade brings in, bundles typings with rolldown-plugin-dts. It cannot parse the inferred type, and the library build fails with PARSE_ERROR in fromTask.d.ts.

Verification

  • A consumer importing fromTask, compiled with tsc 5.9.3 and moduleResolution: "bundler": the 20.0.1 and 20.1.0 typings fail with the error in @angular/build: TS2307: Cannot find module 'firebase/compat' #3677, and the 21.0.0-rc.1 typings and this branch's build compile. With node10 resolution all of them compile, which matches the report that the older builder works.
  • main with the Angular 22 upgrade applied (Angular 22.2.1, ng-packagr 22.2.4) fails to build with PARSE_ERROR in fromTask.d.ts, and builds once the return type is added.

There are no new tests, since a declared return type has no runtime behavior. The Angular 22 build covers it once that upgrade lands.

fromTask declared no return type, so the published typings import
whatever path the typings bundler picks for the inferred firebase
type. In 20.x that is 'firebase/compat', which firebase's exports map
does not list. Apps using moduleResolution "bundler", the setting the
@angular/build migration moves apps to, fail with TS2307 in
@angular/fire/compat/storage. 21.0.0-rc.1 happens to emit
'firebase/compat/app' and compiles, but ng-packagr 22.2's new typings
bundler cannot parse the inferred type and fails the library build.

Declaring Observable<UploadTaskSnapshot> removes the inferred import.
The type is unchanged: UploadTaskSnapshot is the compat alias for
firebase.storage.UploadTaskSnapshot.

Also drop a comment explaining a firebase import that angular#3421 removed
in 2023 as unused. The import only existed to steer these typings.

Fixes angular#3677
@armando-navarro armando-navarro added backport: 20.1.x Cherry-pick onto the 20.1.x branch for a 20.1 patch release bump: patch Size of the change: a fix or docs change that reaches users comp: compat Compatibility layer for the pre-modular API (src/compat). comp: storage Cloud Storage (src/storage). comp: typings TypeScript type correctness across the public API. type: bug Defect: expected behavior doesn't happen. labels Oct 8, 2026
@armando-navarro armando-navarro added this to the 21.0.0-rc.2 milestone Oct 8, 2026

@tyler-reitz tyler-reitz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, with one suggestion.

Checked the chain against the artifacts rather than the description. The 20.0.1 and 20.1.0 typings do declare fromTask returning a type imported from 'firebase/compat', firebase's exports map lists ./compat/app but no ./compat, and that import is TS2307 under moduleResolution: "bundler" while compiling fine under node10, which matches the report that the older builder works. 21.0.0-rc.1 imports 'firebase/compat/app', so it resolves. The build from this branch emits Observable<UploadTaskSnapshot> and imports only resolvable paths, and since the emitted typings alias UploadTaskSnapshot to firebase.storage.UploadTaskSnapshot, the public type is unchanged. I did not reproduce the ng-packagr 22.2 PARSE_ERROR.

The suggestion: the return type is load-bearing and nothing now says so. Deleting the old comment is right, the import it described is gone, but a later cleanup could drop the annotation as redundant and quietly bring #3677 back. The existing fromTask spec pins the element type by assigning each snapshot to a firebase.storage.UploadTaskSnapshot, but that type is identical either way, so it cannot catch how the emitted typings spell it, and by your own note the real coverage arrives with the Angular 22 build. A line like "declared so the typings do not import an inferred firebase/compat path, see #3677" would hold the fix in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport: 20.1.x Cherry-pick onto the 20.1.x branch for a 20.1 patch release bump: patch Size of the change: a fix or docs change that reaches users comp: compat Compatibility layer for the pre-modular API (src/compat). comp: storage Cloud Storage (src/storage). comp: typings TypeScript type correctness across the public API. type: bug Defect: expected behavior doesn't happen.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@angular/build: TS2307: Cannot find module 'firebase/compat'

2 participants