Back to questions
JuniorTheoryCommon
What does tsc report for this file?
interface Box { width: number }
interface Box { height: number }
const b: Box = { width: 2 };
console.log(b.width);An error: the object has no property height
- Expecting a duplicate-name error, as with two
typealiases: interfaces of one name merge into one type with the members of both. - Expecting the second declaration to replace the first: the members add up, so
Boxneeds bothwidthandheight.
- What does tsc report if the second declaration also gives
widththe typestring? - Why can two
typealiases of one name not merge the same way?