oxc-project/oxc · warning · OxcDiagnostic
The generic type arguments should be specified as part of th
Error message
The generic type arguments should be specified as part of the constructor type arguments.
What it means
Warning from typescript/consistent-generic-constructors via ..._prefer_constructor() (crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs:32). With the option 'prefer-constructor-type-arguments', generic type arguments belong on the constructor call; it fires when they appear on the variable's type annotation while the constructor call omits them.
Source
Thrown at crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs:32
use serde::{Deserialize, Serialize};
use crate::{
AstNode,
context::LintContext,
fixer::RuleFixer,
rule::{DefaultRuleConfig, Rule},
};
fn consistent_generic_constructors_diagnostic_prefer_annotation(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(
"The generic type arguments should be specified as part of the type annotation.",
)
.with_help("Move the generic type to the type annotation")
.with_label(span)
}
fn consistent_generic_constructors_diagnostic_prefer_constructor(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(
"The generic type arguments should be specified as part of the constructor type arguments.",
)
.with_help("Move the type annotation to the constructor")
.with_label(span)
}
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ConsistentGenericConstructors(PreferGenericType);
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
enum PreferGenericType {
/// Type arguments that only appear on the type annotation are disallowed.
#[default]
Constructor,
/// Type arguments that only appear on the constructor are disallowed.
TypeAnnotation,
}View on GitHub (pinned to e1e7af627c)
Solutions
- Move the type arguments onto the constructor: 'const m = new Map<string, number>();'
- Apply the rule's autofix (fixer uses RuleFixer) across the codebase in one commit
- If the annotation style is preferred, revert the config to the default 'prefer-type-annotation'
Example fix
// before const roles: Map<string, Role> = new Map(); // after const roles = new Map<string, Role>();
Defensive patterns
Strategy: validation
Validate before calling
const ANNOTATED_NEW = /:\s*\w+(?:<[^>]+>)?\s*=\s*new\s+\w+\s*\(\s*\)\s*;/;
for (const line of source.split('\n')) {
if (ANNOTATED_NEW.test(line)) fail('annotation carries generics; move them to the constructor', line);
} Prevention
- Pin the config to one style before scaling the team
- Codemod existing declarations with oxlint --fix in a single reviewable commit
- Keep .tsx/.ts conventions documented alongside the option
When it happens
Trigger: oxlint runs with 'constructor-type': 'prefer-constructor-type-arguments' and sees 'const m: Map<string, number> = new Map();' — the annotation carries the generics instead of 'new Map<string, number>()'.
Common situations: Switching the config from the default annotation style to constructor style; onboarding code written by teams whose convention is explicit instantiation; editors auto-adding quick-fix types on assignment.
Related errors
- The generic type arguments should be specified as part of th
- Type can be trivially inferred from the initializer
- Prefer using inline type specifiers instead of a top-level t
- Prefer using a top-level type-only import instead of inline
- Prefer using a top-level type-only import instead of inline
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/c22114a89045b849.
Report an issue: GitHub.