org.sonar.l10n.javascript.rules.javascript.S6598.html Maven / Gradle / Ivy
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
- TypeScript Documentation - Function Type
Expressions