Angular is built using TypeScript. What is the main reason Angular requires TypeScript instead of plain JavaScript?
Think about how TypeScript helps developers before the app runs.
TypeScript adds static typing and other features that help catch mistakes early, making Angular apps more reliable and easier to maintain.
Consider an Angular component written in plain JavaScript without TypeScript features. What is the most likely outcome?
Think about Angular's build process and how it uses decorators and types.
Angular relies on TypeScript features like decorators and static typing. Using plain JavaScript without these will cause compilation errors.
Which TypeScript feature is essential for Angular's dependency injection system to work properly?
Angular uses special syntax to tell which classes or parameters should be injected.
Decorators like @Injectable and @Component tell Angular which classes and parameters participate in dependency injection.
Look at this Angular component code snippet:
import { Component } from '@angular/core';
@Component({
selector: 'app-sample',
template: `{{message}}
`
})
export class SampleComponent {
message: string;
constructor() {
this.message = 123;
}
}Why does this code fail to compile?
Check the type of 'message' and what value it gets assigned.
TypeScript enforces that 'message' must be a string, but assigning a number causes a type error.
Angular components implement lifecycle hooks like ngOnInit. How does TypeScript improve the use of these hooks?
Think about how TypeScript interfaces help with method correctness.
TypeScript interfaces let Angular developers implement lifecycle hooks with correct method names and parameters, catching mistakes early.