2021-04-28 16:49:39 +02:00
Union and intersection types are convenient but can make code harder to read and maintain. So if a particular union or intersection is used in multiple places, the use of a type alias is recommended.
2021-04-28 18:08:03 +02:00
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
function foo(x:string|null|number) { // Noncompliant
// ...
}
function bar(x:string|null|number) {
// ...
}
function zoo(): string|null|number {
return null;
}
----
2021-04-28 18:08:03 +02:00
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
type MyType = string | null | number;
function foo(x: MyType) {
// ...
}
function bar(x: MyType) {
// ...
}
function zoo(): MyType {
return null;
}
----
2021-04-28 18:08:03 +02:00
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]