
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
50 lines
1.1 KiB
Plaintext
50 lines
1.1 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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
|
|
|
|
[source,javascript]
|
|
----
|
|
function foo() : any { // Noncompliant
|
|
return 1;
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
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[]
|