36 lines
1.3 KiB
Plaintext

== Why is this an issue?
The TypeScript programming language supports _generics_, a programming construct for creating reusable components, that is, components that can work over various types rather than a single one. Sometimes, we need to limit this genericity to a specific set of types, typically when we know these types share common capabilities, e.g., a `length` property. To this end, the language provides the `extends` clause to describe type constraints on type parameters, whether for classes, interfaces, type aliases, or functions.
By default, a type parameter extends the `any` type. It is therefore redundant to explicitly extend from `any` and should be removed accordingly.
== How to fix it
Fixing such an issue involves removing the redundant type constraint to `any`.
=== Code examples
==== Noncompliant code example
[source,typescript,diff-id=1,diff-type=noncompliant]
----
class C<T extends any> {
// ...
}
----
==== Compliant solution
[source,typescript,diff-id=1,diff-type=compliant]
----
class C<T> {
// ...
}
----
== Resources
=== Documentation
* TypeScript Documentation - https://www.typescriptlang.org/docs/handbook/2/generics.html[Generics]
* TypeScript Documentation - https://www.typescriptlang.org/docs/handbook/2/generics.html#generic-constraints[Generic Constraints]