Skip to content

Input coercion static members cannot be used with NGC and strictMetadataEmit enabled #33451

Closed
@devversion

Description

@devversion

🐞 bug report

Affected Package

@angular/compiler-cli

Is this a regression?

No

Description

Switching between ngtsc and ngc is not possible when coercion static members are declared for components. e.g.

class MyComp {
  ...

  static ngAcceptInputType_disabled: boolean | string;
}

This works as expected in ngtsc, but as soon as the project is compiled with ngc, the metadata validator throws an exception:

Error encountered in metadata generated for exported symbol 'MyComp': 
 /home/circleci/ng/src/cdk/my-comp.ts:422:10: 

Metadata collected contains an error that will be reported at runtime: Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler.
  {"__symbolic":"error","message":"Variable not initialized","line":421,"character":9}

The error for the static members is actually valid since it only happens if strictMetadataEmit is enabled.. and this means that NGC validates that there is no unresolved symbol in the source file metadata. Though, since libraries want to keep that flag enabled to ensure that the metadata works in all cases, we need a way to skip accept coercion members for Ivy/ViewEngine compatibility.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions