oxc-project/oxc · error · OxcDiagnostic
constraining the generic type {generic_type:?} to {constrain
Error message
constraining the generic type {generic_type:?} to {constraint:?} does nothing and is unnecessary What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/typescript/no_unnecessary_type_constraint.rs:21
ast::{TSType, TSTypeParameter, TSTypeParameterDeclaration},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{FileExtension, Span};
use crate::{
AstNode,
context::{ContextHost, LintContext},
rule::Rule,
};
fn no_unnecessary_type_constraint_diagnostic(
generic_type: &str,
constraint: &str,
span: Span,
constraint_span: Span,
) -> OxcDiagnostic {
OxcDiagnostic::warn(format!(
"constraining the generic type {generic_type:?} to {constraint:?} does nothing and is unnecessary"
))
.with_help(format!("Remove the unnecessary {constraint:?} constraint"))
.with_labels([span, constraint_span])
}
#[derive(Debug, Default, Clone)]
pub struct NoUnnecessaryTypeConstraint;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow unnecessary constraints on generic types.
///
/// ### Why is this bad?
///
/// Generic type parameters (`<T>`) in TypeScript may be "constrained" with an `extends`
/// keyword. When no `extends` is provided, type parameters default a constraint to `unknown`.View on GitHub (pinned to e1e7af627c)
Solutions
- Remove the `extends any`/`extends unknown` constraint from the type parameter.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/typescript/no_unnecessary_type_constraint.rs:21 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/2f65e4f2e9765243.
Report an issue: GitHub.