Bird
0
0

Find the error in this Angular TypeScript snippet:

medium📝 Debug Q7 of 15
Angular - TypeScript in Angular
Find the error in this Angular TypeScript snippet:
interface Person {
name: string;
age: number;
}
const p: Person = {
name: 'Bob',
age: '30'
};
ANo error, object matches interface
BError: Type 'string' is not assignable to type 'number' for age
CError: Missing semicolon after age property
DError: Interface Person is not declared properly
Step-by-Step Solution
Solution:
  1. Step 1: Check interface property types

    age must be a number according to Person interface.
  2. Step 2: Check object property types

    age is assigned a string '30', causing a type error.
  3. Final Answer:

    Error: Type 'string' is not assignable to type 'number' for age -> Option B
  4. Quick Check:

    Interface type mismatch = C [OK]
Quick Trick: Interface properties must match assigned types [OK]
Common Mistakes:
  • Ignoring string vs number mismatch
  • Thinking missing semicolon causes error
  • Assuming interface declaration is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes