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,

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

You can use it inside metadata as an expression,

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

The compiler treats the macro expression as it written directly

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

February 17, 2022
561