# prefer-promise-try

Rule `unicorn/prefer-promise-try`. Prefer `Promise.try()` over promise-wrapping boilerplate.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #1077 by reach, #1332 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-promise-try` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-promise-try.md) |

## Code examples

### Incorrect: the rule reports this

```js
new Promise(resolve => resolve(fn()));
```

```js
new Promise(resolve => resolve(fn(argument)));
```

```js
Promise.resolve().then(fn);
```

### Correct: the rule accepts this

```js
Promise.try(() => fn());
```

```js
Promise.try(() => fn(argument));
```

```js
Promise.try(fn);
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-promise-try": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/prefer-private-class-fields](https://lintradar.dev/rules/unicorn/prefer-private-class-fields.md): Prefer private class fields over the underscore-prefix convention.
- [unicorn/prefer-regexp-exec](https://lintradar.dev/rules/unicorn/prefer-regexp-exec.md): Prefer `RegExp#exec()` over `String#match()` for non-global regular expressions.
- [unicorn/prefer-options-parameter](https://lintradar.dev/rules/unicorn/prefer-options-parameter.md): Prefer an options object over optional positional parameters.
- [unicorn/prefer-scoped-selector](https://lintradar.dev/rules/unicorn/prefer-scoped-selector.md): Prefer `:scope` when using element query selector methods.
- [unicorn/prefer-observer-apis](https://lintradar.dev/rules/unicorn/prefer-observer-apis.md): Prefer observer APIs over resize and scroll listeners with layout reads.
- [unicorn/prefer-simple-condition-first](https://lintradar.dev/rules/unicorn/prefer-simple-condition-first.md): Prefer simple conditions first in logical expressions.

---

Web page: https://lintradar.dev/rules/unicorn/prefer-promise-try. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
