50 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
The return type ``++any++`` should be avoided because it prevents the type safety checks normally done by the compiler. When a function returns a primitive type (i.e. number, string or boolean) it is safe to replace ``++any++`` with ``++number++``, ``++string++`` or ``++boolean++`` type respectively, or remove the return type completely and let compiler infer it.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
function foo() : any { // Noncompliant
return 1;
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
function foo() {
return 1;
}
// or
function foo(): number {
return 1;
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this return type or change it to a more specific.
'''
== Comments And Links
(visible only on this page)
=== on 14 Nov 2017, 21:00:55 Ann Campbell wrote:
\[~jeanchristophe.collet] this description would be better if it included a hint about when ``++any++`` is acceptable, and about why boilerplate code is bad.
endif::env-github,rspecator-view[]