Skip to content
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

feat: allow default value for result #41

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

sujyotraut
Copy link
Contributor

Hello,

I’ve been utilizing this library for some time and recently encountered an issue. When a promise is rejected, I would like it to return a default value to allow my program to proceed. However, JavaScript does not assign a default value during destructuring when the value is null. To address this, I’ve substituted null with undefined.

I’m not certain if this project is open to pull requests, but I wanted to offer this change for consideration. Please feel free to disregard this pull request if contributions are not currently being accepted.

Best regards

import { noTryAsync } from 'no-try';

const [_, result = 'DEFAULT_VALUE'] = await noTryAsync(
    () => Promise.reject(new Error('An unexpected error occurred')), 
    err => console.log(`errorMessage: ${err.message}`)
);

// Before: null
console.log(`result: ${result}`);

// After: DEFAULT_VALUE
console.log(`result: ${result}`);

@Coly010
Copy link
Owner

Coly010 commented Apr 12, 2024

Hi @sujyotraut !

Thanks for the contribution. Yes it's always open to PRs.

However, this package definitely needs some love regarding dependencies being out of date.

Let me sort those out first and then I can merge this :)

BREAKING CHANGE: Return `undefined` instead of `null` for default value to allow reassignment when destructuring
@Coly010 Coly010 force-pushed the allow-default-value-for-result branch from fd75bfa to 2f38562 Compare April 12, 2024 12:29
@Coly010 Coly010 changed the title Allow default value for result feat: allow default value for result Apr 12, 2024
@Coly010 Coly010 merged commit 9c71c95 into Coly010:master Apr 12, 2024
1 check passed
github-actions bot pushed a commit that referenced this pull request Apr 12, 2024
# [4.0.0](v3.2.0...v4.0.0) (2024-04-12)

### Features

* replace `null` with `undefined` ([#41](#41)) ([9c71c95](9c71c95))

### BREAKING CHANGES

* Return `undefined` instead of `null` for default value to allow reassignment when destructuring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants