Issue
After updating typescript from 2.3 to 2.6, I see this error in several of my typings. What does it actually mean ? Can you give me an example ?
EDIT:
I understand that this message indicates erroneous interface extension/implementation. I'm more interesting in the meaning of no properties in common
. The suggested question shows an example of a class that implements an interface. What I've seen is an interface extending another interface and changing type of one of the properties. What does it have to do with the message ?
Solution
TypeScript 2.4 introduced stronger checking of weak types, e.g. an interface where all properties are optional.
Suppose we have two weak types with different properties:
interface A {
a?: string;
}
interface B {
b?: string;
}
let x: A = {};
let y: B = {};
Notice that both x
and y
are empty objects that satisfy their respective weak types A
and B
.
Now, is it a mistake to assign an A
to a B
?
y = x;
TypeScript 2.4+ says yes, this is a mistake:
Type 'A' has no properties in common with type 'B'.
This is a simplified example; your typings file is certainly more complex but I hope this illustrates the intent of the error. If you post some code, we can dig into it further.
If TypeScript's weak type checking is being over-cautious in your case, there are workarounds such as casting or using an index signature:
https://blog.mariusschulz.com/2017/12/01/typescript-2-4-weak-type-detection
Answered By - Robert Penner
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.