Comments (12)
This suggests opposite thing to #56293
from angular.
This suggests opposite thing to #56293
Yes, i had just thought of tooling diagnostic error detecting this as alternative, but turns out this had already been suggested 18 hours ago.
These are not 100% exclusive.
The quirk suggested there[1], could be treated as suggested there, whereas defaulted calling could come from here.
P.S.
[1]
<button (click)="void incrementAndLaterDecrement()">Increment</button>
<button (click)="incrementAndLaterDecrement();">Increment</button>
from angular.
One could even consider combining defaulted calling from here with a diagnostic warning (rather than error suggested in #56293)
from angular.
Extended diagnostics are configurable w.r.t. being an error, warning or skipped altogether.
from angular.
OK, i updated my comment to mention warning only for now.
P.S. Although info could be another feature. :)
from angular.
I updated Alternatives considered section in the OP, to make the issue more legible.
from angular.
I think an extended diagnostic is probably the right answer here.
Trying to detect whether an expression in an event listener should be auto-called by the framework is a blurry proposition. For example:
(foo)="bar" // probably meant to call it
(foo)="bar.baz" // probably meant to be a call, but also is a method tearoff if strictly interpreted
(foo)="a && b" // also a side-effect free expression, but did you mean (a && b)() or a() && b()
(foo)="getCallback()" // you probably wanted getCallback()() but that's super hard to infer
Instead, I think it's better to report an error when we detect that an expression evaluates to a callable type but is not called.
from angular.
I updated Alternatives considered section in the OP, to make the issue more legible.
Twice.
from angular.
That's why i've been saying they are not 100% exclusive. Considering continuum of 4 approaches i listed in Alternatives considered in the OP a few minutes ago:
(foo)="bar" // probably meant to call it
approach 1.
ts (foo)="bar.baz" // probably meant to be a call, but also is a method tearoff if strictly interpreted
iff you are saying we can't reliably conclude that this means bar.baz() (but is there a real use-case of that?), (then it won't be approach 1.,) but (rather can be) approach 4.
(foo)="a && b" // also a side-effect free expression, but did you mean (a && b)() or a() && b()
approach 4.
(foo)="getCallback()" // you probably wanted getCallback()() but that's super hard to infer
That's a separate issue out of scope of this issue (because there are "()"), but mentioned as a quirk previously (#56305 (comment)): it's treatment should be discussed separately (should probably even be split off of #56293, because it's not the main thing discussed there, but a fringe case).
from angular.
Although not exactly the same, i'd like to point out that lambda expressions, method calls & just function names can work equivalently in standard JS. E.g.,
a. https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event#examples
function doSomething() {
console.info("DOM loaded");
}
if (document.readyState === "loading") {
// Loading hasn't finished yet
document.addEventListener("DOMContentLoaded", doSomething);
} else {
// `DOMContentLoaded` has already fired
doSomething();
}
b. https://jsfiddle.net/haqer/8Lpganh5/76/
document.getElementById("add").addEventListener("click", handleNew);
from angular.
Different area, but perhaps there is a similarity in this seeming example of approach 2 from gpg domain:
gpg -o test.pdf test.pdf.gpg
gpg: WARNING: no command supplied. Trying to guess what you mean ...
...
File 'test.pdf' exists. Overwrite? (y/N) y
...
P.S. The similarity is in automated deducted action (in this case with a notification).
from angular.
Like it been pointed, we're choosing to go in the opposite direction cf #56293 (WIP implementation #56295).
Also the example about addEventListener
is different. It expect a function, not something you could or not invoke.
from angular.
Related Issues (20)
- NgOptimizedImage `TOO_MANY_PRIORITY_ATTRIBUTES` warning not produced in routed components
- pollyfill.io vulnerability issue affect any angular applications ? is there any pollyfill configuration changes required in angular.json? HOT 2
- `eventCoalescing` breaks things in a `fakeAsync` test
- `@let` fails when declared and used in `ng-container` HOT 2
- Can't download tutorial code HOT 1
- Signals Effect don't run inside asynchronous or condition. HOT 2
- Routed components get services from the wrong injector HOT 1
- Safari problem HOT 1
- Lazy Loading in Angular V18, Page Not Found Error Displayed. HOT 1
- Clicking on a link does not change content HOT 4
- ADEV: Angular DevTools page is missing a section about hydration support
- ADEV: rework "Programmatically rendering components" section to mention `@defer`
- ADEV: add an index page for the Performance section
- @angular/elements component use input.required<string>() not `Signal` type but `string` type HOT 1
- Content of a tab in adev-reference-page is hidden on reload HOT 1
- Make HostAttributeToken more modern like new input/output HOT 2
- Download icon for Default app starter zip code button not working in Angular.dev HOT 1
- Compatibility issue with chrome HOT 1
- Navigation problem HOT 1
- toObservable doesn't make input signals synchronous HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular.