{"record":{"id":"902d1c56c5b2c6a8","repo":"oxc-project/oxc","slug":"do-not-use-new-on-promise-static-name","errorCode":null,"errorMessage":"Do not use `new` on `Promise.{static_name}`","messagePattern":"Do not use `new` on `Promise\\.(.+?)`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/promise/no_new_statics.rs","lineNumber":9,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule, utils::PROMISE_STATIC_METHODS};\n\nfn static_promise_diagnostic(static_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Do not use `new` on `Promise.{static_name}`\"))\n        .with_help(format!(\n            \"`Promise.{static_name}` is not a constructor. Call it as a function instead.\"\n        ))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoNewStatics;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows calling new on static `Promise` methods.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Calling a static `Promise` method with `new` is invalid and will result\n    /// in a `TypeError` at runtime.","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/promise/no_new_statics.rs#L1-L27","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Muscle memory from `new Promise(executor)` applied to the shorter static forms; autocomplete inserting `new`; porting snippets between promise construction styles.","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'"],"exampleFix":"// before\nconst p = new Promise.all([fetchA(), fetchB()])\n\n// after\nconst p = Promise.all([fetchA(), fetchB()])","handlingStrategy":"type-guard","validationCode":"npx oxlint --promise/no-new-statics src/\n# and at compile time:\ntsc --noEmit  # ts(2350): This expression is not constructable.","typeGuard":"// TypeScript's lib.es2015.promise.d.ts declares statics without construct signatures,\n// so `new Promise.resolve(x)` fails type-check with ts(2350).\n// Guard = keep files inside a tsconfig project and run `tsc --noEmit` in CI.","tryCatchPattern":"// last-resort runtime containment while fixing the code:\ntry {\n  const p = new Promise.all(xs)\n} catch (e) {\n  if (e instanceof TypeError && /not a constructor/.test(e.message)) {\n    // statics are plain functions - drop `new`\n  }\n  throw e\n}","preventionTips":["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"],"tags":["promise","async","lint","runtime-error","oxlint"],"backgroundTag":"new-on-non-constructor","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}