Skip to content

Add a new rule to enforce a method syntax #1598

@nstepien

Description

@nstepien

Recently I found out that the shorthand method syntax is looser type-wise than the non-shorthand syntax:

interface MyInterface {
  fn1(num: number | undefined): void;
  fn2: (num: number | undefined) => void;
}

const badObject: MyInterface = {
  fn1(num: number) {}, // no error??
  fn2(num: number) {} // error
}

const shouldBeBadObject: MyInterface = {
  fn1(num: number) {}, // no error??
  fn2(num: number | undefined) {}
}

const goodObject: MyInterface = {
  fn1(num: number | undefined) {},
  fn2(num: number | undefined) {}
}

Would it make sense to add a new @typescript-eslint/eslint-plugin rule to enforce the non-/shorthand syntax?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: new plugin ruleNew rule request for eslint-pluginhas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions