{"record":{"id":"2f65e4f2e9765243","repo":"oxc-project/oxc","slug":"constraining-the-generic-type-generic-type-to","errorCode":null,"errorMessage":"constraining the generic type {generic_type:?} to {constraint:?} does nothing and is unnecessary","messagePattern":"constraining the generic type (.+?) to (.+?) does nothing and is unnecessary","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/typescript/no_unnecessary_type_constraint.rs","lineNumber":21,"sourceCode":"    ast::{TSType, TSTypeParameter, TSTypeParameterDeclaration},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{FileExtension, Span};\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::Rule,\n};\n\nfn no_unnecessary_type_constraint_diagnostic(\n    generic_type: &str,\n    constraint: &str,\n    span: Span,\n    constraint_span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"constraining the generic type {generic_type:?} to {constraint:?} does nothing and is unnecessary\"\n    ))\n    .with_help(format!(\"Remove the unnecessary {constraint:?} constraint\"))\n    .with_labels([span, constraint_span])\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoUnnecessaryTypeConstraint;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow unnecessary constraints on generic types.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Generic type parameters (`<T>`) in TypeScript may be \"constrained\" with an `extends`\n    /// keyword. When no `extends` is provided, type parameters default a constraint to `unknown`.","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/no_unnecessary_type_constraint.rs#L3-L39","documentation":"Raised by typescript/no-unnecessary-type-constraint when a generic type parameter is constrained to its default implicit bound, e.g. <T extends any> or <T extends unknown>. The constraint adds no restriction.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/typescript/no_unnecessary_type_constraint.rs:21 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the `extends any`/`extends unknown` constraint from the type parameter."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}