-
Notifications
You must be signed in to change notification settings - Fork 895
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
Can't import error TypeScript types for AuthErrorCode #4551
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
The file you're looking at is part of the experimental modular auth package that's currently in alpha, which is still undergoing some changes. @samhorlbeck @Feiyang1 We currently aren't exporting this enum publicly out of auth-exp I think because it's a large enum that we've made a Also is it a good idea to add the definition to packages/firebase/index.d.ts for the current (non-exp) typings? |
I think it would be tricky to expose the enum from an API perspective (we'd have to stick with One thing we could consider doing is exposing these error codes as individual export const AUTH_ERROR_NETWORK_REQUEST_FAILED = 'auth/network-request-failed'; This would allow tree shaking and compatibility with JS/TS both. Still not the ideal dev experience, however |
For the modular SDK, we can export an object map which is tree shakable, but we should continue to use const enum internally. |
I didn't think object maps were tree shakable |
I'm not very technical/experience with Typescript and firebase. But if I was writing error codes myself for my own Typescript code I could do something like...
This gets completely erased when compiling to javascript. I'd then get intellisense to see the list of possible error codes and would get a warning if I did it wrong. Won't help javascript developers though. |
I think for the original example you gave you'd ideally want an object map or enum so you could do As for object maps not being tree shakeable I think maybe @Feiyang1 meant that the developer could just not import the map at all if they are not using the error codes, in which case, the entire map would be tree shaken out? |
Yes you are right. I'd prefer |
Made a PR to do this for the current auth package: #4579 The change for the modularized (exp) version would be totally different and can be done in another PR if we decide on an approach. |
Yes, I meant it can be tree shaken out if developer didn't import it. @samhorlbeck , See the rollup repl. |
I guess my concern is that folks import the whole map without realizing what a big addition it is (only to use one or two strings out of it). There are use cases for checking the error code in production, so it's not just something you'd do while debugging either. |
We've decided to provide this as an object map in the upcoming modularized version of Firebase, which is in alpha now and should be released soon. In light of that, we won't provide it in the current version of auth, as it will increase the bundle size for all users, which is already a common concern. In the modularized version, users can decide whether to import it and incur the size increase. |
Great. I’ve been surprised how responsive the google team has been to suggestions.
…________________________________
From: Christina Holland ***@***.***>
Sent: Monday, March 15, 2021 8:46:53 AM
To: firebase/firebase-js-sdk ***@***.***>
Cc: Justin Magaram ***@***.***>; Author ***@***.***>
Subject: Re: [firebase/firebase-js-sdk] Can't import error TypeScript types for AuthErrorCode (#4551)
We've decided to provide this as an object map in the upcoming modularized version of Firebase, which is in alpha now and should be released soon. In light of that, we won't provide it in the current version of auth, as it will increase the bundle size for all users, which is already a common concern. In the modularized version, users can decide whether to import it and incur the size increase.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#4551 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADLZYS7J2EAQDNP2UFEYCFLTDZIZ3ANCNFSM4YKL23XQ>.
|
Hey! Wondering what's the deal with this now in 2023? Spent the past half hour trying to find a way to get at the FirebaseAuthError type so that I don't have to access |
This issue was about the AuthErrorCodes enum which is available:
There's also an
And do an instanceof check, if your check does not need to narrow down which specific firebase product threw the error. If you're just trying to cast it (and don't need instanceof), I think |
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
I'm trying to code some auth stuff in a TypeScript Angular project, like
this.auth.signOut();
andthis.auth.signInAnonymously();
. I'm trying to catch the errors but there seems to be no way to strongly type them using TypeScript. So I need to do code like this but can't use TypeScript intellisense to browse the available errors and get no warning if the error code string I use does not exist.The error codes are documented in...
https://firebase.google.com/docs/reference/node/firebase.auth.Error
I can see that every error is defined in this file in an
enum AuthErrorCode
https://github.com/firebase/firebase-js-sdk/blob/20a88da5d935fdb8c1ff38e358c84e1939145abb/packages-exp/auth-exp/src/core/errors.ts
..But this is not publicly/easily accessible in my code. The package these are in says "This package is not intended for direct usage".
PLEASE make all the error codes accessible through a package I can import. Ideally I could get at the Enum.
The text was updated successfully, but these errors were encountered: