Bird
0
0

Consider the interface and object below:

medium📝 Debug Q7 of 15
Angular - TypeScript in Angular
Consider the interface and object below:

interface Movie { title: string; duration: number; }
const myMovie: Movie = { title: 'Inception' };

What is the issue with this code?
AThe property <code>title</code> should be a number, not a string
BThe object is missing the required property <code>duration</code>
CThe interface should not have any properties
DThe object has an extra property not defined in the interface
Step-by-Step Solution
Solution:
  1. Step 1: Check interface requirements

    The interface Movie requires both title (string) and duration (number).
  2. Step 2: Analyze object assignment

    The object myMovie only provides title, missing duration.
  3. Final Answer:

    The object is missing the required property duration -> Option B
  4. Quick Check:

    Missing required properties cause TypeScript errors. [OK]
Quick Trick: All required interface properties must be present in object [OK]
Common Mistakes:
  • Assuming missing properties are optional by default
  • Confusing property types
  • Ignoring TypeScript compile errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes