Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
devversion opened this issue Oct 28, 2019 · 3 comments
Labels
area: compiler Issues related to `ngc`, Angular's template compiler freq2: medium hotlist: components team Related to Angular CDK or Angular Material type: bug/fix
Milestone

Comments

@devversion
Copy link
Member

devversion commented Oct 28, 2019

🐞 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.

@devversion devversion added the hotlist: components team Related to Angular CDK or Angular Material label Oct 28, 2019
@devversion devversion changed the title ngtsc input coercion static members cannot be used with ngc Input coercion static members cannot be used with NGC and strictMetadataEmit enabled Oct 28, 2019
devversion added a commit to devversion/material2 that referenced this issue Oct 29, 2019
devversion added a commit to devversion/material2 that referenced this issue Oct 29, 2019
devversion added a commit to devversion/material2 that referenced this issue Oct 29, 2019
devversion added a commit to devversion/material2 that referenced this issue Oct 29, 2019
devversion added a commit to devversion/material2 that referenced this issue Oct 29, 2019
Workaround for angular/angular#33451. This makes
sense at the current time since the Bazel output does *never* work with
strict metadata emit... and considering that with Ivy there is no metadata
anyway, it could be disabled in the meanwhile.
devversion added a commit to devversion/material2 that referenced this issue Oct 30, 2019
devversion added a commit to devversion/material2 that referenced this issue Oct 30, 2019
Workaround for angular/angular#33451. This makes
sense at the current time since the Bazel output does *never* work with
strict metadata emit... and considering that with Ivy there is no metadata
anyway, it could be disabled in the meanwhile.
devversion added a commit to devversion/material2 that referenced this issue Oct 30, 2019
devversion added a commit to devversion/material2 that referenced this issue Oct 30, 2019
Workaround for angular/angular#33451. This makes
sense at the current time since the Bazel output does *never* work with
strict metadata emit... and considering that with Ivy there is no metadata
anyway, it could be disabled in the meanwhile.
devversion added a commit to devversion/material2 that referenced this issue Oct 31, 2019
devversion added a commit to devversion/material2 that referenced this issue Oct 31, 2019
Workaround for angular/angular#33451. This makes
sense at the current time since the Bazel output does *never* work with
strict metadata emit... and considering that with Ivy there is no metadata
anyway, it could be disabled in the meanwhile.
devversion added a commit to devversion/material2 that referenced this issue Oct 31, 2019
devversion added a commit to devversion/material2 that referenced this issue Oct 31, 2019
Workaround for angular/angular#33451. This makes
sense at the current time since the Bazel output does *never* work with
strict metadata emit... and considering that with Ivy there is no metadata
anyway, it could be disabled in the meanwhile.
devversion added a commit to devversion/material2 that referenced this issue Oct 31, 2019
devversion added a commit to devversion/material2 that referenced this issue Oct 31, 2019
Workaround for angular/angular#33451. This makes
sense at the current time since the Bazel output does *never* work with
strict metadata emit... and considering that with Ivy there is no metadata
anyway, it could be disabled in the meanwhile.
andrewseguin pushed a commit to angular/components that referenced this issue Oct 31, 2019
…checking (#17528)

* feat: expand input types with coercion to work with ngtsc input type checking

* refactor: add workaround for strict metadata emit of coercion static members

See: angular/angular#33451

* build: patch ng_module bazel rule to enable strict template type checking

Workaround for: angular/angular#33452

* refactor: disable strict metadata emit for legacy build output

Workaround for angular/angular#33451. This makes
sense at the current time since the Bazel output does *never* work with
strict metadata emit... and considering that with Ivy there is no metadata
anyway, it could be disabled in the meanwhile.

* build: disable strict attribute type checking

We are temporarily disabling strict attribute type checking
since we have a few templates that set a coerced input while
the `NgModel` directive is applied. In those cases, the empty string
for the `disabled` input, is not assignable to the `NgModel#disabled` input,
since it does not do coercion. We need to figure out what to do in those
scenarios.
@atscott atscott added the area: compiler Issues related to `ngc`, Angular's template compiler label Nov 1, 2019
@ngbot ngbot bot added this to the needsTriage milestone Nov 1, 2019
@alxhub
Copy link
Member

alxhub commented Dec 5, 2019

Maybe just assign it to null!?

@alxhub
Copy link
Member

alxhub commented Jan 28, 2020

Fixed in #34296.

@alxhub alxhub closed this as completed Jan 28, 2020
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler freq2: medium hotlist: components team Related to Angular CDK or Angular Material type: bug/fix
Projects
None yet
Development

No branches or pull requests

3 participants