Skip to content

Invalid "Use an interface instead of a type literal" warning? #15123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
letorbi opened this issue Apr 11, 2017 · 4 comments
Closed

Invalid "Use an interface instead of a type literal" warning? #15123

letorbi opened this issue Apr 11, 2017 · 4 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@letorbi
Copy link

letorbi commented Apr 11, 2017

TypeScript Version: 2.2.1

Code

interfaces.ts

interface IKeyValue {
  [key: string]: string;
}

interface IParent {
  foo?: IKeyValue;
  goo?: string;
}

// works

export interface ITestA extends IParent {
  foo?: {
    bar: string,
  };
}

// warning

type TFoo = {
  bar: string,
};

export interface ITestB extends IParent {
  foo?: TFoo;
}

// error
/*
interface IFoo {
    bar: string;
};

interface ITestC extends IParent {
  foo: IFoo;
}
*/

export class TestInline {
  public testA: ITestA;
  public testB: ITestB;
  // public testC: ITestC;

  public foo() {
    return 'foo';
  }
}

anywhere else

import {TestInline} from 'interfaces';

const ti = new TestInline();

Expected behavior:

If the warning "Use an interface instead of a type literal" is thrown, I should be able to replace the type literal by an interface without causing an error. If type and interface are not equivalent such a warning should not be thrown.

Actual behavior:

When I'm replacing the type literal at interface.ts line 19 with an interface definition (see commented out code), the compiler throws an error: [33:11] Interface 'ITestC' incorrectly extends interface IParent [...] Index signature is missing in type 'IFoo'.

@ajafff
Copy link
Contributor

ajafff commented Apr 11, 2017

Are you sure this warning comes from typescript? I'd guess that's coming from the tslint rule interface-over-type-literal https://palantir.github.io/tslint/rules/interface-over-type-literal/

@RyanCavanaugh RyanCavanaugh added the External Relates to another program, environment, or user action which we cannot control. label Apr 11, 2017
@RyanCavanaugh
Copy link
Member

Indeed this is from TSLint.

@letorbi
Copy link
Author

letorbi commented Apr 11, 2017

Oh, sorry for the hassle...

@letorbi
Copy link
Author

letorbi commented May 2, 2017

@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

3 participants