persona-community-5/.pnpm-store/v3/files/4e/fa3e5e5e4ac63e533201aa3ec3256c56d748cbf3b857429dcf131370fade58324e7419da9fb5776563ec1d632733cbffa266b78337679846a12731ad3013cf
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

62 lines
1.3 KiB
Plaintext

---
description: 'Disallow unnecessary constraints on generic types.'
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/no-unnecessary-type-constraint** for documentation.
Generic type parameters (`<T>`) in TypeScript may be "constrained" with an [`extends` keyword](https://www.typescriptlang.org/docs/handbook/generics.html#generic-constraints).
When no `extends` is provided, type parameters default a constraint to `unknown`.
It is therefore redundant to `extend` from `any` or `unknown`.
## Examples
<Tabs>
<TabItem value="❌ Incorrect">
```ts
interface FooAny<T extends any> {}
interface FooUnknown<T extends unknown> {}
type BarAny<T extends any> = {};
type BarUnknown<T extends unknown> = {};
class BazAny<T extends any> {
quxAny<U extends any>() {}
}
const QuuxAny = <T extends any>() => {};
function QuuzAny<T extends any>() {}
```
</TabItem>
<TabItem value="✅ Correct">
```ts
interface Foo<T> {}
type Bar<T> = {};
class Baz<T> {
qux<U>() {}
}
const Quux = <T>() => {};
function Quuz<T>() {}
```
</TabItem>
</Tabs>
## When Not To Use It
If you don't care about the specific styles of your type constraints, or never use them in the first place, then you will not need this rule.