All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S6598.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

TypeScript allows declaring the type of a function in two different ways:

  • Function type: () ⇒ number
  • Object type with a call signature: { (): number }

The function type syntax is generally preferred for being more concise.

How to fix it

Use a function type instead of an interface or object type literal with a single call signature.

Code examples

Noncompliant code example

function apply(f: { (): string }): string {
  return f();
}

Compliant solution

function apply(f: () => string): string {
  return f();
}

Noncompliant code example

interface Foo {
  (): number;
}

Compliant solution

type Foo = () => number;

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy