Search code examples
typescripttypescript-eslint

typescript/eslint rule for function syntax in objects implementing interface


JavaScript (and TypeScript) offers two ways to define functions when letting an object implement an interface. Consider this code sample:

export interface ITest {
    start(): ITest;
    stop(): ITest;
}

const instance: ITest = {
    start: () => instance,
    stop() { return this; },
}

I'd like to enforce a consistent code style and need to disable the second style (without :). Is there a typescript-eslint rule for that?


Solution

  • I looked through the typescript-eslint rules list but unfortunately I couldn't identify anything from the rule names that seemed to fit what you are looking for.

    Here's the full rules list from their repository: https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/docs/rules