{"record":{"id":"461980f5eaefa663","repo":"oxc-project/oxc","slug":"the-generic-type-arguments-should-be-specified-as","errorCode":null,"errorMessage":"The generic type arguments should be specified as part of the type annotation.","messagePattern":"The generic type arguments should be specified as part of the type annotation\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs","lineNumber":24,"sourceCode":"        TSTypeParameterInstantiation, TSTypeReference,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::IsGlobalReference;\nuse oxc_span::{GetSpan, Span};\nuse schemars::JsonSchema;\nuse 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)]","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs#L6-L42","documentation":"Warning from typescript/consistent-generic-constructors via ..._prefer_annotation() (crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs:24). With the default option 'prefer-type-annotation', generic type arguments belong on the variable's type annotation, not on the constructor call; it fires when a constructor call like 'new Map<string, number>()' supplies them instead.","triggerScenarios":"oxlint runs with the default (or explicit) 'constructor-type' = 'prefer-type-annotation' and sees 'const m = new Map<string, number>();', 'const a = new Array<string>()', or 'new Set<Foo>()' where the type arguments sit on the constructor expression.","commonSituations":"Enabling recommended configs on a codebase that habitually writes 'new Map<K,V>()' inline; code copied from documentation examples that parameterize the constructor; mixed styles after merging teams.","solutions":["Move the type arguments to the annotation: 'const m: Map<string, number> = new Map();'","Normalize the codebase with a codemod (ast-grep or a lint --fix pass, since this rule provides a fixer via RuleFixer)","If your team prefers constructor args, set 'prefer-constructor-type-arguments' in .oxlintrc.json"],"exampleFix":"// before\nconst roles = new Map<string, Role>();\n\n// after\nconst roles: Map<string, Role> = new Map();","handlingStrategy":"validation","validationCode":"const CTOR_GENERICS = /=\\s*new\\s+\\w+\\s*<[^>]+>\\s*\\(/;\nfor (const line of source.split('\\n')) {\n  if (CTOR_GENERICS.test(line)) fail('generics on constructor; move to type annotation', line);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize one constructor-type style in .oxlintrc.json","Let the editor's inferred-type quick-fix add annotations instead of typing 'new Map<...>'","Apply the rule's autofix repo-wide once when adopting it"],"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"}