Skip to content

Commit 96c0e42

Browse files
fix(core): allow readonly arrays for standalone imports (#47851)
Standalone components should support readonly arrays in the `@Component.imports`. Fixes #47643 PR Close #47851
1 parent f24da6b commit 96c0e42

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

goldens/public-api/core/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export interface Component extends Directive {
188188
encapsulation?: ViewEncapsulation;
189189
// @deprecated
190190
entryComponents?: Array<Type<any> | any[]>;
191-
imports?: (Type<any> | any[])[];
191+
imports?: (Type<any> | ReadonlyArray<any>)[];
192192
interpolation?: [string, string];
193193
moduleId?: string;
194194
preserveWhitespaces?: boolean;

packages/core/src/metadata/directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ export interface Component extends Directive {
629629
* More information about standalone components, directives, and pipes can be found in [this
630630
* guide](guide/standalone-components).
631631
*/
632-
imports?: (Type<any>|any[])[];
632+
imports?: (Type<any>|ReadonlyArray<any>)[];
633633

634634
/**
635635
* The set of schemas that declare elements to be allowed in a standalone component. Elements and

packages/core/test/acceptance/standalone_spec.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('standalone components, directives, and pipes', () => {
152152
});
153153

154154

155-
it('should render a standalone component with dependenices and ambient providers', () => {
155+
it('should render a standalone component with dependencies and ambient providers', () => {
156156
@Component({
157157
standalone: true,
158158
template: 'Inner',
@@ -453,6 +453,34 @@ describe('standalone components, directives, and pipes', () => {
453453
expect(fixture.nativeElement.innerHTML).toBe('<div red="true">blue</div>');
454454
});
455455

456+
it('should support readonly arrays in @Component.imports', () => {
457+
@Directive({selector: '[red]', standalone: true, host: {'[attr.red]': 'true'}})
458+
class RedIdDirective {
459+
}
460+
461+
@Pipe({name: 'blue', pure: true, standalone: true})
462+
class BluePipe implements PipeTransform {
463+
transform() {
464+
return 'blue';
465+
}
466+
}
467+
468+
const DirAndPipe = [RedIdDirective, BluePipe] as const;
469+
470+
@Component({
471+
selector: 'standalone',
472+
standalone: true,
473+
template: `<div red>{{'' | blue}}</div>`,
474+
imports: [DirAndPipe],
475+
})
476+
class TestComponent {
477+
}
478+
479+
const fixture = TestBed.createComponent(TestComponent);
480+
fixture.detectChanges();
481+
expect(fixture.nativeElement.innerHTML).toBe('<div red="true">blue</div>');
482+
});
483+
456484
it('should deduplicate declarations', () => {
457485
@Component({selector: 'test-red', standalone: true, template: 'red(<ng-content></ng-content>)'})
458486
class RedComponent {

0 commit comments

Comments
 (0)