Extending Incompatible Properties
Here we have a pair of types called UserPart
and UserPart2
:
type UserPart = { id: string; name: string; age: number;};type UserPart2 = { id: number; phone: string;};
Notice that the id
property in UserPart
is a string, but in UserPart2
it's a number.
These two
Transcript
00:00 In this exercise we have a pair of types here. We have user parts and user part two. These happen to have a couple of incompatible properties here. So it has a user ID string on user part one and ID number on user parts two.
00:14 Then we're combining those two user parts together to make a user here. And then we have a little error down the bottom, which is type string is not assignable to type never. Your job is to work out how we can better structure this so that we actually get an error in a different position.
00:33 We actually don't want to make the error go away because we could do that very simply. We could just say ID is a string here, right on user part two. But your job is to work out how we can better get this error surfaced so we can actually see it more readily and get rid of that error. And the way to do it is actually to use interfaces instead of types.