Skip to content

Array of cooperating directives throws error with standalone flag on #47643

@Jefiozie

Description

@Jefiozie

Which @angular/* package(s) are the source of the bug?

compiler, core

Is this a regression?

No

Description

When working on a library I found the need to export a set of directives to cooperate together. Based on the documentation array of cooperating directives this should be possible when using the following approach.

export const dirs = [MakeItBlueDirective, MakeItRedDirective] as const;

The result of this is that the compiler (I think) will throw an error:

Type 'readonly [typeof MakeItBlueDirective, typeof MakeItRedDirective]' is not assignable to type 'any[] | Type<any>'.
  The type 'readonly [typeof MakeItBlueDirective, typeof MakeItRedDirective]' is 'readonly' and cannot be assigned to the mutable type 'any[]'.ts(2322)

Using a NgModule or directly import both directives everything works as expected. A workaround that I found together with @SanderElias is that removing as const is working. But we believe that this is not should be done.

A minimal repo can be found here: minimal repo
The line that needs to be changed to use the array of directives is here
A minimal repo with v15-next.4 can be found here minimal repo next branch

side note: we checked with @pkozlowski-opensource and he recommended making this issue

Please provide a link to a minimal reproduction of the bug

https://github.com/Jefiozie/standalone-directive-imports

Please provide the exception or error you saw

Type 'readonly [typeof MakeItBlueDirective, typeof MakeItRedDirective]' is not assignable to type 'any[] | Type<any>'.
  The type 'readonly [typeof MakeItBlueDirective, typeof MakeItRedDirective]' is 'readonly' and cannot be assigned to the mutable type 'any[]'.ts(2322)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 14.2.4
Node: 16.13.0
Package Manager: npm 8.1.0 
OS: linux x64

Angular: 14.2.4
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1402.4
@angular-devkit/build-angular   14.2.4
@angular-devkit/core            14.2.4
@angular-devkit/schematics      14.2.4
@schematics/angular             14.2.4
rxjs                            7.5.7
typescript                      4.6.4

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimecross-cutting: standaloneIssues related to the NgModule-less world

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions