36 lines
600 B
Plaintext
Raw Normal View History

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 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 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;
}
----