oxc-project/oxc · error · OxcDiagnostic
`Promise.{prop_name}()` requires 1 or 2 arguments, but recei
Error message
`Promise.{prop_name}()` requires 1 or 2 arguments, but received {args_len}. What it means
Diagnostic from the oxlint rule `promise/valid-params` (plugin `promise`, category `correctness`). It fires when `.then(...)` is called with an argument count other than 1 or 2 (0 callbacks, or 3+). `then` takes an optional fulfillment handler and an optional rejection handler - a third argument does nothing, and zero arguments means the call is a pure no-op that still allocates a new promise.
Source
Thrown at crates/oxc_linter/src/rules/promise/valid_params.rs:24
use crate::{AstNode, context::LintContext, rule::Rule, utils::is_promise_with_context};
fn zero_or_one_argument_required_diagnostic(
span: Span,
prop_name: &str,
args_len: usize,
) -> OxcDiagnostic {
OxcDiagnostic::warn(format!(
"`Promise.{prop_name}()` requires 0 or 1 arguments, but received {args_len}."
))
.with_label(span)
}
fn one_or_two_argument_required_diagnostic(
span: Span,
prop_name: &str,
args_len: usize,
) -> OxcDiagnostic {
OxcDiagnostic::warn(format!(
"`Promise.{prop_name}()` requires 1 or 2 arguments, but received {args_len}."
))
.with_label(span)
}
fn one_argument_required_diagnostic(span: Span, prop_name: &str, args_len: usize) -> OxcDiagnostic {
OxcDiagnostic::warn(format!(
"`Promise.{prop_name}()` requires 1 argument, but received {args_len}."
))
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct ValidParams;
declare_oxc_lint!(
/// ### What it does
///View on GitHub (pinned to e1e7af627c)
Solutions
- Pass exactly one or two handler functions to `then`
- Move cleanup logic to `.finally(fn)` instead of a third `then` argument
- Delete empty `.then()` links from the chain
- Add `tsc --noEmit` to CI so arity errors surface at compile time
Example fix
// before p.then(onSuccess, onFailure, onFinally) // after p.then(onSuccess, onFailure).finally(onFinally)
Defensive patterns
Strategy: type-guard
Validate before calling
npx oxlint --promise/valid-params src/ tsc --noEmit # flags then() with 0 or 3+ args via ts(2554)
Type guard
// lib signature: then<TResult1, TResult2>( // onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, // onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null // ): PromiseLike<TResult1 | TResult2>; // exactly 2 optional params - a 3rd arg fails tsc
Prevention
- Give `then` one or two handlers only; use `.finally()` for cleanup
- Delete empty `.then()` no-ops left by refactors
- Keep `tsc --noEmit` in CI to catch arity drift at compile time
When it happens
Trigger: `somePromise().then()` (0 args); `somePromise().then(a, b, c)` (3+ args); `promiseReference.then(() => {}, () => {}, () => {})`.
Common situations: Passing a third callback intended as a finally-style handler; refactoring that deleted the callback but left `.then()`; spreading arrays of handlers into `then`.
Related errors
- `Promise.{prop_name}()` requires 0 or 1 arguments, but recei
- `Promise.{prop_name}()` requires 1 argument, but received {a
- Promise executor functions should not be `async`.
- Unexpected `await` inside a loop.
- Avoid nesting promises.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/e5ea916bf53b689e.
Report an issue: GitHub.