Repository navigation
fix(storage): give the compat fromTask an explicit return type - #3796
armando-navarro wants to merge 1 commit into
Conversation
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
tyler-reitz
left a comment
There was a problem hiding this comment.
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.
Fixes #3677
This gives the compat
fromTaskan explicit return type, so the published@angular/fire/compat/storagetypings stop depending on how the typings bundler names an inferred Firebase type.Changes
fromTaskinsrc/compat/storage/observable/fromTask.tsdeclaresObservable<UploadTaskSnapshot>. The type is unchanged:UploadTaskSnapshotis the compat alias forfirebase.storage.UploadTaskSnapshot.firebaseimport that add eslint #3421 removed in 2023.20.1.x, so a 20.1 patch release fixes @angular/build: TS2307: Cannot find module 'firebase/compat' #3677 for apps on thelatesttag.Why
Without a declared return type, the typings import whatever module path the bundler picks for the inferred type:
'firebase/compat'. Thefirebasepackage'sexportsmap has no./compatentry, so apps usingmoduleResolution: "bundler"fail withTS2307: Cannot find module 'firebase/compat'. Angular'suse-application-buildermigration switches apps to that setting, which is how @angular/build: TS2307: Cannot find module 'firebase/compat' #3677 ran into it.'firebase/compat/app', which resolves, so it compiles.rolldown-plugin-dts. It cannot parse the inferred type, and the library build fails withPARSE_ERRORinfromTask.d.ts.Verification
fromTask, compiled withtsc5.9.3 andmoduleResolution: "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. Withnode10resolution all of them compile, which matches the report that the older builder works.mainwith the Angular 22 upgrade applied (Angular 22.2.1, ng-packagr 22.2.4) fails to build withPARSE_ERRORinfromTask.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.