-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Better IoC support #21531
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
Comments
This is a breaking change into 2.7 version if you use strict mode. To disable it, set |
Yes, I'm aware of that. This is more of a proposal to work with the flag on. |
How about this? import { Component } from '@angular/component';
@Component({})
export class MyComponent {
private a!: string; // notice the exclamation mark!
ngOnInit() {
this.a = 1
}
} or am I missing the point? |
I didn't mentioned it above. But the proposal is so you don't have to use the definite assignment operator The compiler should trust that the framework will construct and initialize variables if I configured them to do so. Right now, the compiler doesn't trust the framework and I shouldn't have to opt-out of strict checking because it can't. I hope this clarifies things |
Similar discussion in #20740. I do not think we would add a new syntax just to disable checking of uninitialized properties.. this is an opt-in feature, and users can chose to enable it (or disable it under |
I've read before that you where considering a syntax for it? #20740 (comment) I get your point, but I think people(including me) want to opt-in using Now, if I upgrade my project to the new version of TS, I have to either opt-out with Feels a bit that proposals being declined without being read or thought nor letting other have time to leave their comments. |
no it is not a hack, and it is not temporary.. they are cases that the compiler does not know. they are cases, where the init function is called multiple times, and there are cases, where
That is why you have two means of disabling this check.. you need to decide what is more economical for you.. either you disable it across the whole code base, or you opt-out specific classes.
that is not true. we have been discussing this issue for a few month now.. so I can claim that i have thought about many of these issues already, and considered them. |
I appreciate all the hard work you done and I know the TS team have put a lot of effort on this. I was meaning more that any proposal, in this case that maybe is an improvement, are declined very fast. I put some hours on my free time writing this proposal as well. Because it was declined so instantly, I can only interpret it as you don't want to listen to any or the proposal was bad. |
The issue is open, and i am replying, and others are reading.. so no one is opposed to listening... We have discussed similar proposals in the past, that is all. |
And the decline label? |
We have discussed similar proposals in the past and decided not to do them. hence the declined label. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
It would be nice if TS could be more IoC friendly. One of the main pains I have with it, is that it doesn't know an alternative constructor:
Here we annotate a secondary
constructor
onIComponent
:And then we instructs the class to implement it, note the use of
implements
keyword:And then, all people can be happy:
For property decorators, we currently face this problem:
Here we introduce the
initializes
keyword:Other frameworks are built the other way around, instead of another disjoint function or class providing the construction of the class, a base class provides it. So we could theoretically write our component like below(if we disregard the class annotations ):
And we should be able to achieve the same thing using a base class:
The text was updated successfully, but these errors were encountered: