{"record":{"id":"c22114a89045b849","repo":"oxc-project/oxc","slug":"the-generic-type-arguments-should-be-specified-as-c22114","errorCode":null,"errorMessage":"The generic type arguments should be specified as part of the constructor type arguments.","messagePattern":"The generic type arguments should be specified as part of the constructor type arguments\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs","lineNumber":32,"sourceCode":"use serde::{Deserialize, Serialize};\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    fixer::RuleFixer,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn consistent_generic_constructors_diagnostic_prefer_annotation(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"The generic type arguments should be specified as part of the type annotation.\",\n    )\n    .with_help(\"Move the generic type to the type annotation\")\n    .with_label(span)\n}\n\nfn consistent_generic_constructors_diagnostic_prefer_constructor(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"The generic type arguments should be specified as part of the constructor type arguments.\",\n    )\n    .with_help(\"Move the type annotation to the constructor\")\n    .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]\npub struct ConsistentGenericConstructors(PreferGenericType);\n\n#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]\n#[serde(rename_all = \"kebab-case\")]\nenum PreferGenericType {\n    /// Type arguments that only appear on the type annotation are disallowed.\n    #[default]\n    Constructor,\n    /// Type arguments that only appear on the constructor are disallowed.\n    TypeAnnotation,\n}","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs#L14-L50","documentation":"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.","triggerScenarios":"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>()'.","commonSituations":"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.","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'"],"exampleFix":"// before\nconst roles: Map<string, Role> = new Map();\n\n// after\nconst roles = new Map<string, Role>();","handlingStrategy":"validation","validationCode":"const ANNOTATED_NEW = /:\\s*\\w+(?:<[^>]+>)?\\s*=\\s*new\\s+\\w+\\s*\\(\\s*\\)\\s*;/;\nfor (const line of source.split('\\n')) {\n  if (ANNOTATED_NEW.test(line)) fail('annotation carries generics; move them to the constructor', line);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["typescript","oxlint","lint","generics","constructor","type-annotation","style"],"backgroundTag":"generic-constructor-annotation-style","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"}