Skip to content

Commit 2b718aa

Browse files
committed
Clarify the usage of const enums and enum maps in auth.
1 parent f5aec7b commit 2b718aa

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/auth/src/model/public_types.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export interface ActionCodeInfo {
416416
/**
417417
* The type of operation that generated the action code.
418418
*/
419-
operation: typeof ActionCodeOperationMap[keyof typeof ActionCodeOperationMap];
419+
operation: (typeof ActionCodeOperationMap)[keyof typeof ActionCodeOperationMap];
420420
}
421421

422422
/**
@@ -541,6 +541,9 @@ export interface AuthProvider {
541541
/**
542542
* An enum of factors that may be used for multifactor authentication.
543543
*
544+
* Internally we use an enum type for FactorId, ActionCodeOperation, but there is a copy in https://github.com/firebase/firebase-js-sdk/blob/48a2096aec53a7eaa9ffcc2625016ecb9f90d113/packages/auth/src/model/enum_maps.ts#L23 that uses maps.
545+
* const enums are better for tree-shaking, however can cause runtime errors if exposed in public APIs, example - https://github.com/microsoft/rushstack/issues/3058
546+
* So, we expose enum maps publicly, but use const enums internally to get some tree-shaking benefit.
544547
* @internal
545548
*/
546549
export const enum FactorId {
@@ -589,7 +592,7 @@ export interface ConfirmationResult {
589592
*/
590593
export interface MultiFactorAssertion {
591594
/** The identifier of the second factor. */
592-
readonly factorId: typeof FactorIdMap[keyof typeof FactorIdMap];
595+
readonly factorId: (typeof FactorIdMap)[keyof typeof FactorIdMap];
593596
}
594597

595598
/**
@@ -629,7 +632,7 @@ export interface MultiFactorError extends AuthError {
629632
/**
630633
* The type of operation (sign-in, linking, or re-authentication) that raised the error.
631634
*/
632-
readonly operationType: typeof OperationTypeMap[keyof typeof OperationTypeMap];
635+
readonly operationType: (typeof OperationTypeMap)[keyof typeof OperationTypeMap];
633636
};
634637
}
635638

@@ -646,7 +649,7 @@ export interface MultiFactorInfo {
646649
/** The enrollment date of the second factor formatted as a UTC string. */
647650
readonly enrollmentTime: string;
648651
/** The identifier of the second factor. */
649-
readonly factorId: typeof FactorIdMap[keyof typeof FactorIdMap];
652+
readonly factorId: (typeof FactorIdMap)[keyof typeof FactorIdMap];
650653
}
651654

652655
/**
@@ -1049,7 +1052,7 @@ export interface UserCredential {
10491052
/**
10501053
* The type of operation which was used to authenticate the user (such as sign-in or link).
10511054
*/
1052-
operationType: typeof OperationTypeMap[keyof typeof OperationTypeMap];
1055+
operationType: (typeof OperationTypeMap)[keyof typeof OperationTypeMap];
10531056
}
10541057

10551058
/**

0 commit comments

Comments
 (0)