-
Notifications
You must be signed in to change notification settings - Fork 25.9k
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
feat(compiler-cli): Support template binding to protected component members #45823
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). For more information, open the CLA check for this pull request. |
9641f04
to
8f190fe
Compare
@JoostK JFYI - I think the test failures on CircleCI are real failures that we don't want. I think the original diagnostic messages are correct. Looking into it, but LMK if you have any thoughts. It looks like we're hitting this scenario: http://typescriptlang.org/docs/handbook/2/classes.html#cross-hierarchy-protected-access. |
I think the scenario is essentially this:
where the expression
Previously, before this PR, the error read:
Which is I think much clearer. Are these diagnostic messages user-facing? If so, this new error message might be a problem. Otherwise, maybe it's fine to just update the test assertion to expect the new error message. |
Those errors are indeed user-facing; we only translate the TS diagnostics to their original template location but we use the messages directly. Interestingly, this behaviour was changed in microsoft/TypeScript#47991 for TS 4.7 and if you switch the playground over to Nightly you'll find that the error is as it used to be. We've only switched the repo over to TS 4.7 in the last couple days and it is super strange that the |
Nice find! What's the best path forward then? It sounds like we need to determine why |
I just SSH'd into the Windows box to see what's going on, and the root cause is that the Windows CI job does not use the rebased checkout, unlike the Linux test jobs (the rebase is done in the |
8f190fe
to
46d8e94
Compare
Great, looks like that resolved it. |
@JoostK, regarding this:
I haven't been able to get this addendum to work. Here's a playground that demonstrates. Am I missing something? Note that we can still use string index notation to work around this (and also bind to EDIT: Maybe we can do something like this: Another playground. Not sure if this breaks other stuff. |
The idea of the I see two possibilities, one of which actually seems to work:
We can get rid of the |
5d0272e
to
2d30eec
Compare
Yep, makes sense. Changed to an arrow function, removed the |
|
@@ -585,6 +585,29 @@ class TestComponent { | |||
expect(messages).toEqual( | |||
[`TestComponent.html(3, 30): Type 'HTMLElement' is not assignable to type 'string'.`]); | |||
}); | |||
|
|||
it('allows access to protected members', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be similar tests for @Directive
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe there's any template type-checking associated with directives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alxhub This thread made me think of host attribute bindings and whether it was possible today to create a host attribute binding to a protected/private member. From my testing on StackBlitz, it looks like it's already possible (which surprised me).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't type-check host bindings at all at the moment (not since Ivy, at least; VE had limited type-checking of host bindings)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that sounds like something for the backlog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! It would be great if you could also update the README.md
file to reflect the changes.
packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts
Outdated
Show resolved
Hide resolved
2d30eec
to
33e4d29
Compare
…embers This commit adds support for creating template bindings to protected members within the component class.
33e4d29
to
6435323
Compare
I realized I think I'm "dismissing" these reviews with my force pushes (rebasing + force pushing to avoid a ton of noisy commits). Please LMK if this isn't the right workflow for future reference! |
g3sync PR looks good except for some already failing targets. |
@zelliott we just turned on a new branch protection feature that dismisses all approvals when new commits are pushed as a security safeguard. For the time being, this prevents the "lgtm with nits" workflow until we add some additional tooling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This PR was merged into the repository by commit 752ddbc. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
(unclear if any docs need to be updated)
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently, you can not create a template binding to a protected component member. For example:
Issue Number: N/A
What is the new behavior?
Now, the code above compiles.
Does this PR introduce a breaking change?
Other information