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

58 lines
1.7 KiB
Plaintext

== Why is this an issue?
The TypeScript type system offers a basic support for composite types:
* _Union Types_ represent a value that can be one of the several types. They are constructed using a vertical bar (``++|++``) like the following ``++type NumberOrString = number | string++``.
* _Intersection Types_ combine multiple types into one, so that the object of such type will have all the members of all intersection type elements. They are constructed using an ampersand (``++&++``) like the following ``++type SerializablePerson = Person & Serializable++``. Intersection Types are often used to represent mixins.
Duplicating types when defining a union or interaction type makes the code less readable. Moreover duplicated types might be a simple mistake and another type should be used instead.
=== Noncompliant code example
[source,javascript]
----
function padLeft(value: string, padding: string | number | string) { // Noncompliant; 'string' type is used twice in a union type declaration
// ...
}
function extend(p : Person) : Person & Person & Loggable { // Noncompliant; 'Person' is used twice
// ...
}
----
=== Compliant solution
[source,javascript]
----
function padLeft(value: string, padding: string | number | boolean) {
// ...
}
function extend(p : Person) : Person & Loggable {
// ...
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this duplicated type or replace with another one.
=== Highlighting
First: second occurrence of the element
Second: first occurrence ("Original"), third and all other occurrences ("Another duplicate")
endif::env-github,rspecator-view[]