Skip to content

noEmptyTypeParameters

诊断类别:lint/complexity/noEmptyTypeParameters

¥Diagnostic Category: lint/complexity/noEmptyTypeParameters

自从:v1.5.0

¥Since: v1.5.0

禁止类型别名和接口中的空类型参数。

¥Disallow empty type parameters in type aliases and interfaces.

TypeScript 允许在类型别名和接口声明中使用空类型参数列表;但是,通常不鼓励这种做法。允许空类型参数列表可能会导致代码不明确或模棱两可,其中泛型类型的意图不言而喻。此规则不允许在类型别名和接口声明中使用空的类型参数列表。

¥TypeScript permits the use of empty type parameter lists in type alias and interface declarations; however, this practice is generally discouraged. Allowing empty type parameter lists can lead to unclear or ambiguous code, where the intention of the generic type is not self-evident. This rule disallows empty type parameter lists in type alias and interface declarations.

¥Examples

¥Invalid

interface Foo<> {}
code-block.ts:1:14 lint/complexity/noEmptyTypeParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Using an empty type parameter list is confusing.

> 1 │ interface Foo<> {}
^^
2 │

Remove the empty type parameter list or add a type parameter.

type Bar<> = {};
code-block.ts:1:9 lint/complexity/noEmptyTypeParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Using an empty type parameter list is confusing.

> 1 │ type Bar<> = {};
^^
2 │

Remove the empty type parameter list or add a type parameter.

¥Valid

interface Foo {}
type Foo<T> = {
bar: T;
}

¥Related links