Skip to content

Commit

Permalink
fix: Update return types and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bayotop committed May 28, 2024
1 parent 1fb0d72 commit f80ae38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/sources/apple_pay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Sources', () => {
ApplePaySession: undefined,
},
async () => {
expect(await getApplePayState()).toBe(ApplePayState.NoAPI)
expect(getApplePayState()).toBe(ApplePayState.NoAPI)
},
)
})
Expand Down
15 changes: 7 additions & 8 deletions src/sources/apple_pay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const enum ApplePayState {
NotAvailableInFrame = -3,
}

/**
* The return type is a union instead of the enum, because it's too challenging to embed the const enum into another
* project. Turning it into a union is a simple and an elegant solution.
*/
export default function getApplePayState(): 0 | 1 | -1 | -2 | -3 {
const { ApplePaySession } = window

Expand All @@ -28,14 +32,9 @@ export default function getApplePayState(): 0 | 1 | -1 | -2 | -3 {
}
}

/**
* The return type is a union instead of the enum, because it's too challenging to embed the const enum into another
* project. Turning it into a union is a simple and an elegant solution.
*
* Warning for package users:
* This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
*/
export function getStateFromError(error: unknown): -2 | -3 {
export function getStateFromError(
error: unknown,
): Exclude<ApplePayState, ApplePayState.Disabled | ApplePayState.Enabled | ApplePayState.NoAPI> {
if (error instanceof Error) {
// See full expected error messages in the test
if (error.name === 'InvalidAccessError') {
Expand Down

0 comments on commit f80ae38

Please sign in to comment.