Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to extend empty interface but getting lint error: no-empty-interface

Today, I tried to do this in my angular 6 application:

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;
}

And got a lint error:

An empty interface is equivalent to `{}`. (no-empty-interface)

I wanted to do this with my Endpoint interface:

Export interface Endpoint {
…
authConfig: AuthConfig;
…
}

But was reduced to doing this:

Export interface Endpoint {
…
authConfig: BasicAuthConfig | OAuth2AuthConfig;
…
}

The different types of authorization could get lengthy so I don’t want to keep tacking on the types to the authConfig property of the Endpoint interface. Is there any way to declare an empty interface for the purpose of extending it without lint yelling at me?

Thanks.

like image 661
Gibran Shah Avatar asked Sep 05 '25 20:09

Gibran Shah


2 Answers

You can either disable this rule in tslint.json:

"rules": { "no-empty-interface": false }

Or just disable linting for one line:

// tslint:disable-next-line
export interface AuthConfig {}
like image 194
Borys Kupar Avatar answered Sep 09 '25 11:09

Borys Kupar


How to disable

Example:
$ cat .eslintrc.js
  ...
  "rules": {
  '@typescript-eslint/no-empty-interface': 'off'
  }
  ...
like image 34
oviniciusfeitosa Avatar answered Sep 09 '25 10:09

oviniciusfeitosa