TypeScript uses structural typing rather than nominal typing. What this means is that only the shape matters. URLLike
is defined as a shape with a href
property of type string so absolutely any type that has a href
property of type string will do.
Other languages such as Java are nominally typed and here the name matters. So only types that explicitly said they implement URLLike
would be valid.
You can think about this a bit like compile-time duck typing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…