From afe529cb2d97e766b4f9014c3b6864420b7c8deb Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Wed, 29 Jul 2026 22:40:45 +0000 Subject: [PATCH] fix(core): accept readonly arrays for setClassMetadata decorators When reflection metadata is emitted via setClassMetadata, passing readonly arrays or const tuples for the decorators parameter causes TypeScript type checking errors because setClassMetadata previously expected decorators to be a mutable any[] or null. This change updates the setClassMetadata type signature to accept decorators as readonly any[] or null and casts the parameter internally when mutating the class metadata property. (cherry picked from commit dc65e3656ff56fc6c5c03cf59991a6e8760b5279) --- packages/core/src/render3/interfaces/definition.ts | 3 +-- packages/core/src/render3/metadata.ts | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/core/src/render3/interfaces/definition.ts b/packages/core/src/render3/interfaces/definition.ts index 0b1f44283b1..d2bc1e7729b 100644 --- a/packages/core/src/render3/interfaces/definition.ts +++ b/packages/core/src/render3/interfaces/definition.ts @@ -403,8 +403,7 @@ export interface ComponentDef extends DirectiveDef { * A function used by the framework to create standalone injectors. */ getStandaloneInjector: - | ((parentInjector: EnvironmentInjector) => EnvironmentInjector | null) - | null; + ((parentInjector: EnvironmentInjector) => EnvironmentInjector | null) | null; /** * A function used by the framework to create the list of external runtime style URLs. diff --git a/packages/core/src/render3/metadata.ts b/packages/core/src/render3/metadata.ts index f29fc0e6b3e..e4375d17cc7 100644 --- a/packages/core/src/render3/metadata.ts +++ b/packages/core/src/render3/metadata.ts @@ -86,7 +86,7 @@ export function setClassMetadataAsync( */ export function setClassMetadata( type: any, - decorators: any[] | null, + decorators: readonly any[] | null, ctorParameters: (() => any[]) | null, propDecorators: {[field: string]: any} | null, ): void { @@ -97,7 +97,7 @@ export function setClassMetadata( if (clazz.hasOwnProperty('decorators') && clazz.decorators !== undefined) { clazz.decorators.push(...decorators); } else { - clazz.decorators = decorators; + clazz.decorators = decorators as any[]; } } if (ctorParameters !== null) {