小编Gib*_*hah的帖子

想要扩展空接口但出现 lint 错误:no-empty-interface

今天,我尝试在我的 angular 6 应用程序中执行此操作:

export interface AuthConfig {}

export interface BasicAuthConfig extends AuthConfig {
    username: string;
    password: string;
}

export interface OAuth2AuthConfig extends AuthConfig {
    tokenName: string;
    url: string;
    callbackUrl: string;
    clientId: string;
    scope: string[];
    grantType: grantTypes;
}
Run Code Online (Sandbox Code Playgroud)

并得到一个 lint 错误:

An empty interface is equivalent to `{}`. (no-empty-interface)
Run Code Online (Sandbox Code Playgroud)

我想用我的端点接口做到这一点:

Export interface Endpoint {
…
authConfig: AuthConfig;
…
}
Run Code Online (Sandbox Code Playgroud)

但被简化为这样做:

Export interface Endpoint {
…
authConfig: BasicAuthConfig | OAuth2AuthConfig;
…
}
Run Code Online (Sandbox Code Playgroud)

不同类型的授权可能会变得冗长,因此我不想继续将类型添加到 Endpoint 接口的 authConfig 属性中。有什么方法可以声明一个空接口以扩展它而不会对我大喊大叫吗?

谢谢。

lint interface typescript angular

10
推荐指数
3
解决办法
1万
查看次数

标签 统计

angular ×1

interface ×1

lint ×1

typescript ×1