44 lines
1011 B
Plaintext
44 lines
1011 B
Plaintext
An empty interface is equivalent to an empty object ('{}'). Normally you cannot directly assign an object literal to a type when the object literal contains more properties than are specified in the type. But in the case of an empty interface, this check is not done, and such assignments will be successful. The result is highly likely to confuse maintainers.
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,javascript]
|
|
----
|
|
interface A {} // Noncompliant
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
[source,javascript]
|
|
----
|
|
interface A {
|
|
foo: number;
|
|
}
|
|
----
|
|
|
|
== Exceptions
|
|
|
|
No issue is raised if the empty interface extends a https://www.typescriptlang.org/docs/handbook/utility-types.html[TypeScript utility type].
|
|
|
|
[source,javascript]
|
|
----
|
|
interface A {
|
|
foo: number;
|
|
bar: string;
|
|
}
|
|
|
|
interface B extends Pick<A, 'foo'> {}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|