Back to questions
JuniorTheoryCommon
What does tsc report for this file?
type Point = { x: number; y: number };
const p: Point = { x: 1 };
console.log(p.y);An error: the object has no property y
- Expecting a silent
undefined, as in JavaScript: tsc checks the literal againstPointand reports the missingyon the declaration line. - Expecting a missing number property to start at
0: TypeScript fills nothing in; it only checks that every required property is present.
- How would you change
Pointso thatymay be left out? - What does tsc report if the literal gives
ya string instead of a number?