Gib*_*hah 10 lint interface typescript angular
今天,我尝试在我的 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 属性中。有什么方法可以声明一个空接口以扩展它而不会对我大喊大叫吗?
谢谢。
Bor*_*par 15
您可以在以下位置禁用此规则tslint.json:
"rules": { "no-empty-interface": false }
Run Code Online (Sandbox Code Playgroud)
或者只是禁用一行的 linting:
// tslint:disable-next-line
export interface AuthConfig {}
Run Code Online (Sandbox Code Playgroud)
还有另一种方式:
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AuthConfig {}
Run Code Online (Sandbox Code Playgroud)
Example:
$ cat .eslintrc.js
...
"rules": {
'@typescript-eslint/no-empty-interface': 'off'
}
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10084 次 |
| 最近记录: |