RevenueCat / RevenueCat/react-native-purchases
Vend a typeguard function for checking if an Error is a PurchasesError
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 117
- Avg merge
- 14h 40m
- Merged PRs (30d)
- 40
Description
Hey. When using TypeScript, the type of the caught error is unknown (any in non-strict mode of older versions of TypeScript). It would be very useful to have a typeguard function vended that could narrow the type. Would you be willing to accept a PR that implements this?
export const isPurchasesError = (err: unknown): err is PurchasesError => {
// Implementation here
}
The usage would look like:
try {
await someCodeThatTriggersAPurchase()
} catch (err) {
if (isPurchasesError(err)) {
// Handle PurchasesError here.
// The type will be narrowed by the compiler and IDE completion will work nicely.
} else {
// Handle other errors differently
}
}
This is something we can of course just write on our own end, but it seems like it'd be useful to have as part of the core library here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing PurchasesError type and the package's public TypeScript exports. Define the exported guard so it narrows unknown errors to PurchasesError, then verify that the example catch block receives the narrowed type and that non-PurchasesError values are rejected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native, typescript
- Domain
- api, developer-experience
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100