Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
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.
2023-05-25 14:18:12 +02:00

49 lines
1.3 KiB
Plaintext

== Why is this an issue?
Unlike in JavaScript, where every parameter can be omitted, in TypeScript you need to explicitly declare this in the function signature. Either you add ``++?++`` in the parameter declaration and ``++undefined++`` will be automatically applied to this parameter. Or you add an initializer with a default value in the parameter declaration. In the latter case, when passing ``++undefined++`` for such parameter, default value will be applied as well. So it's better to avoid passing ``++undefined++`` value to an optional or default parameter because it creates more confusion than it brings clarity. Note, that this rule is only applied to the last arguments in function call.
=== Noncompliant code example
[source,javascript]
----
function foo(x: number, y: string = "default", z?: number) {
// ...
}
foo(42, undefined); // Noncompliant
foo(42, undefined, undefined); // Noncompliant
foo(42, undefined, 5); // OK, there is no other way to force default value for second parameter
----
=== Compliant solution
[source,javascript]
----
function foo(x: number, y: string = "default", z?: number) {
// ...
}
foo(42);
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this redundant "undefined".
=== Highlighting
"undefined"
endif::env-github,rspecator-view[]