The TypeScript type system offers a basic support for composite types:
|) like
the following type NumberOrString = number | string. &) 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.
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
// ...
}
function padLeft(value: string, padding: string | number | boolean) {
// ...
}
function extend(p : Person) : Person & Loggable {
// ...
}