49 lines
1021 B
Plaintext
49 lines
1021 B
Plaintext
== Why is this an issue?
|
|
|
|
An intersection type combines multiple types into one. This allows you to add together existing types to get a single type that has all the features you need. However an intersection with a type without members doesn't change the resulting type. In the opposite the usage of ``++any++`` or ``++never++`` as part of an intersection will always results in ``++any++`` or ``++never++`` respectively. This is almost certainly an error.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,javascript]
|
|
----
|
|
function foo(p: MyType & null) { // Noncompliant
|
|
// ...
|
|
}
|
|
|
|
function bar(p: MyType & any) { // Noncompliant
|
|
// ...
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
function foo(p: MyType | null) {
|
|
// ...
|
|
}
|
|
// or
|
|
function foo(p: MyType & AnotherType) {
|
|
// ...
|
|
}
|
|
|
|
function bar(p: any) {
|
|
// ...
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
include::highlighting.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|