src/content/docs/linter/rules/no-useless-type-constraint.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/complexity/noUselessTypeConstraint`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`@typescript-eslint/no-unnecessary-type-constraint`](https://typescript-eslint.io/rules/no-unnecessary-type-constraint){
"linter": {
"rules": {
"complexity": {
"noUselessTypeConstraint": "error"
}
}
}
}
Disallow using any or unknown as type constraint.
Generic type parameters (<T>) in TypeScript may be constrained with extends.
A supplied type must then be a subtype of the supplied constraint.
All types are subtypes of any and unknown.
It is thus useless to extend from any or unknown.
interface FooAny<T extends any> {}
type BarAny<T extends any> = {};
class BazAny<T extends any> {
}
class BazAny {
quxAny<U extends any>() {}
}
const QuuxAny = <T extends any>() => {};
function QuuzAny<T extends any>() {}
interface FooUnknown<T extends unknown> {}
type BarUnknown<T extends unknown> = {};
class BazUnknown<T extends unknown> {
}
class BazUnknown {
quxUnknown<U extends unknown>() {}
}
const QuuxUnknown = <T extends unknown>() => {};
function QuuzUnknown<T extends unknown>() {}
interface Foo<T> {}
type Bar<T> = {};