Skip to content

no-unnecessary-type-constraint

禁止不必要的类型约束

为什么

在TypeScript中,泛型类型参数(<T>)可以使用extends关键字进行“约束”。当没有提供extends时,类型参数默认约束为unknown。因此,从anyunknown进行extend是多余的。

建议

删除不必要的类型约束

错误示例

ts
interface FooAny<T extends any> {}
interface FooAny<T extends any> {}

正确示例

ts
interface Foo<T> {}
interface Foo<T> {}

参考