oxc-project/oxc · error · OxcDiagnostic
Do not use `new` on `Promise.{static_name}`
Error message
Do not use `new` on `Promise.{static_name}` What it means
Diagnostic from the oxlint rule `promise/no-new-statics` (plugin `promise`). It fires on any `new` expression whose callee is a static member of `Promise` (from the PROMISE_STATIC_METHODS surface, e.g. `new Promise.resolve()`, `new Promise.all()`, `new Promise.reject()`). These statics are plain functions, not constructors, so `new` throws `TypeError: Promise.resolve is not a constructor` at runtime when the line executes.
Source
Thrown at crates/oxc_linter/src/rules/promise/no_new_statics.rs:9
use oxc_ast::{AstKind, ast::Expression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{AstNode, context::LintContext, rule::Rule, utils::PROMISE_STATIC_METHODS};
fn static_promise_diagnostic(static_name: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Do not use `new` on `Promise.{static_name}`"))
.with_help(format!(
"`Promise.{static_name}` is not a constructor. Call it as a function instead."
))
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoNewStatics;
declare_oxc_lint!(
/// ### What it does
///
/// Disallows calling new on static `Promise` methods.
///
/// ### Why is this bad?
///
/// Calling a static `Promise` method with `new` is invalid and will result
/// in a `TypeError` at runtime.View on GitHub (pinned to e1e7af627c)
Solutions
- Drop `new` and call the static directly: `Promise.resolve(value)`
- If you truly need a fresh `Promise` instance object, wrap: `Promise.resolve(Promise.all(iterable))`
- Run `tsc --noEmit` alongside oxlint - TypeScript also rejects this with ts(2350) 'This expression is not constructable'
Example fix
// before const p = new Promise.all([fetchA(), fetchB()]) // after const p = Promise.all([fetchA(), fetchB()])
Defensive patterns
Strategy: type-guard
Validate before calling
npx oxlint --promise/no-new-statics src/ # and at compile time: tsc --noEmit # ts(2350): This expression is not constructable.
Type guard
// TypeScript's lib.es2015.promise.d.ts declares statics without construct signatures, // so `new Promise.resolve(x)` fails type-check with ts(2350). // Guard = keep files inside a tsconfig project and run `tsc --noEmit` in CI.
Try / catch
// last-resort runtime containment while fixing the code:
try {
const p = new Promise.all(xs)
} catch (e) {
if (e instanceof TypeError && /not a constructor/.test(e.message)) {
// statics are plain functions - drop `new`
}
throw e
} Prevention
- Only `new Promise(executor)` takes `new`; every `Promise.<static>` is a plain call
- Keep `tsc --noEmit` in CI - it flags non-constructable expressions
- Run `npx oxlint --promise/no-new-statics` in pre-commit hooks
When it happens
Trigger: `const p = new Promise.resolve(value)`; `new Promise.all([a, b])`; any `new Promise.<static>()` where `<static>` is resolve/reject/all/allSettled/any/race/withResolvers/try.
Common situations: Muscle memory from `new Promise(executor)` applied to the shorter static forms; autocomplete inserting `new`; porting snippets between promise construction styles.
Related errors
- Promise executor functions should not be `async`.
- Unexpected `await` inside a loop.
- Avoid nesting promises.
- Avoid using promises inside of callbacks.
- Don't return in a finally callback
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/902d1c56c5b2c6a8.
Report an issue: GitHub.