invertase / invertase/react-native-apple-authentication

AppleError and other enums are not available on runtime

Open
#366 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.7k
Forks
236
PR merge metrics
No merged PRs in 30d

Description

Hi,

I am trying to use the `AppleError` enum in a runtime check, which looks something like this:

```ts
import {
appleAuth,
AppleError
} from '@invertase/react-native-apple-authentication';

...

export function isNativeFirebaseError(
error: any
): error is ReactNativeFirebase.NativeFirebaseError {
return error && error.code && error.message;
}

try {
// do stuff
} catch (err) {
if (isNativeFirebaseError(err) && err.code === AppleError.FAILED) {
// do stuff
}
}
```

The issue is that while the typechecking passes, `AppleError` enum is not available at runtime as it's `declared` in https://github.com/invertase/react-native-apple-authentication/blob/cadd7cad1c8c2c59505959850affaa758328f1a3/lib/index.d.ts#L131

```ts
console.log(AppleError) // undefined
```

However, the code is correctly assigned in the error:

```ts
try {
// do stuff
} catch (err) {
if (isNativeFirebaseError(err) && err.code === "1004") {
// does not throw, it's ok!
}
}
```

This also affects all the other `declared` enums on that file too. I think the easiest fix would be removing the `declare` keyword from the typedef or marking them as `const` instead.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.