InterviewHubPRO
Section Overview
Q88

Question 88 of 283

Part 4: JIT vs AOT Compilation, Metadata & TypeScript (76 - 100)

31%
Angular & Signals (283 Qs)•Part 4: JIT vs AOT Compilation, Metadata & TypeScript (76 - 100)

What are macros?

The AOT compiler supports macros in the form of functions or static methods that return an expression in a single return expression. For example, let us take a below macro function,

javascript
export function wrapInArray<T>(value: T): T[] {
return [value];
}

You can use it inside metadata as an expression,

javascript
@NgModule({
declarations: wrapInArray(TypicalComponent)
})
export class TypicalModule {}

The compiler treats the macro expression as it written directly

javascript
@NgModule({
declarations: [TypicalComponent]
})
export class TypicalModule {}