You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
retain support for TypeScript 2.6 to make g3 upgrade easier
Reacted by Dominique Müller, Exequiel Ceasar Navarrete, Lars Rye Jeppesen, bmayen, David J. M. Karlsen, Anthony Ciccarello, Nicolas HENRY, Martin-Luft, Sylvain Dumont, Bjorn Harvold and 25 more
Reacted by Yiu, sapabg, DRen and Craig Treasure
Reacted by Martín Hosman, Alan Agius and Melroy van den Berg
Until now, when Angular supported a new version of TypeScript, it supported it in strict mode.
But in TS 2.7, --strictPropertyInitialization causes a lot of mess in Angular code, as reported in microsoft/TypeScript#20740. Solutions have been discussed, but nothing seems to be included in the 2.7 release.
On Tue, Jan 23, 2018 at 12:40 AM Cyrille Tuzi ***@***.***> wrote:
Until now, when Angular supported a new version of TypeScript, it
supported it in strict mode.
But in TS 2.7, --strictPropertyInitialization causes a lot of mess in
Angular code, as reported in microsoft/TypeScript#20740
<microsoft/TypeScript#20740>. Solutions have
been discussed, but nothing seems to be included in the 2.7 release.
What's the plans about that ?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#21571 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANM6N8mOkEOMaQUh_AFE0dT4R9CGc0Tks5tNZsSgaJpZM4RgeFi>
.
I discussed the --strictPropertyInitialization flag with @mhevery, considered various options, and came to a conclusion that the flag does the right thing and any kind of special treatment for Angular's @Input fields would be compromising the type model.
Our recommendation is to either don't use the flag, or the better option is to initialize the inputs to a default value or null (which requires | null type union).
This would enable a proper use of --strictPropertyInitialization. I understood from documentation about ngOnInit that this may be needed for change detection but I do not understand why change detection need to be started before all inputs are available.
Setting a default value is not possible for objects, which is a very common case. Setting to null does not only require to set the | null union type, it also forces to add conditions checking if it's null or not for every bit of code using that data. So it's clearly not an option, especially when it's not relevant.
The very classic architecture of Angular is : a controller component get data via a service and pass the data to a presentation component with @Input(). Check is done in the controller component with *ngIf, so we know the @Input() won't be null, and it would be crazy to add conditions checking everywhere just because of TS behavior.
So for me, it's sure it will be the option of not being strict, which is sad. I think it's really weird TS introduced a feature which is not relevant/friendly with one of the bigger project using it (and I suppose Angular won't be the only affected framework/library). As I said in the other discussion, the current logic is "let's the developer change all his/her code (even when it's good code) to manage the problems", when it should be "let's TypeScript manage its own problems".
@cyrilletuzi - I don't think that any check forces you to set the input parameters, so technically marking them as potentially undefined does make sense. I'd rather want to have a possibility within angular to say - these properties need to be set, to have the type check there. The example above, by @nicolashenry would be perfect, if it works like that.
By the way - in case I don't care for implementing a setter for myInput couldn't I directly write
@Component({ selector: 'my-component' })
class MyComponent {
constructor(@Attribute('myInput') @Input('myInput') public myInput: string) { }
}
@cyrilletuzi Nothing forces @Input() to be set. A user of the your component may simply chose not to bind to that input in which case your @Input() is not initialize and you should have checks for non-initialized case. I know we disagree, but I think this is the correct behavior.
What would be nice is to have @Input({required:true}) which would be an error if the user created your component and did not bind to that @Input, but as of yet we don't have such a feature.
Reacted by Yaroslav Admin, Miloš Lapiš, Scott Cooper, ge022, Cameron, Daniel Wegener, Łukasz Samson, Guillermo Prandi, parker-mike, Philippe Plantier and 7 more
Could @Input({required:true}) not be accomplished just using ts somehow? By analyzing the @Input variable type and seeing if undefined is an acceptable type?
Reacted by M. Orçun Topdağı, Georgii Dolzhykov and Łukasz Samson
What would be really nice is that @Input() is required by default, except there is a default value. Like function parameters in TypeScript and quite any language.
But with the actual behavior, yes, there should be a check, and there is one : the *ngIf on the parent controller. So again, when checks are done and the code is good, it's not normal for the developer to have to add more TS specific code just to please TypeScript.
@cyrilletuzi The strictPropertyInitialization option cannot be applied to lib, there’s no such information (constructor implementation) exists to perform that check...
@trotyl I've had to make my way to that block of code in CLI before, to explain the Angular -> TypeScript supported versions. It seems to me that ideally this information would be represented canonically somewhere in Angular core (and then referred to by CLI code) as it seems to me this is inevitably a property of Angular itself that would apply even to non-CLI users. Roughly akin to the browser support information.
To that effect, I know that compiler feature landed somewhere in the road to 6.0 with 3ceee99. My assumption (without having tried it out myself) would be that as long as ngc complains loud enough, the CLI should just stop on its tracks if the TS version is unsupported, and developers can "opt out" to ignore via disableTypeScriptVersionCheck in the angularCompilerOptions.
Activity
cyrilletuzi commentedon Jan 23, 2018
Until now, when Angular supported a new version of TypeScript, it supported it in
strictmode.But in TS 2.7,
--strictPropertyInitializationcauses a lot of mess in Angular code, as reported in microsoft/TypeScript#20740. Solutions have been discussed, but nothing seems to be included in the 2.7 release.What's the plans about that ?
IgorMinar commentedon Jan 23, 2018
IgorMinar commentedon Feb 2, 2018
I discussed the
--strictPropertyInitializationflag with @mhevery, considered various options, and came to a conclusion that the flag does the right thing and any kind of special treatment for Angular's@Inputfields would be compromising the type model.Our recommendation is to either don't use the flag, or the better option is to initialize the inputs to a default value or
null(which requires| nulltype union).nicolashenry commentedon Feb 2, 2018
@IgorMinar
Why can not inputs be defined in the constructor? Like this for example :
This would enable a proper use of
--strictPropertyInitialization. I understood from documentation aboutngOnInitthat this may be needed for change detection but I do not understand why change detection need to be started before all inputs are available.mhevery commentedon Feb 2, 2018
Inputs by definition can change over time. Constructor can only receive one value. But you can use
@Attributein the constructor. Unfortunately someone needs to wire the docs: https://angular.io/api/core/Attribute :-( See spec instead: https://github.com/angular/angular/blob/master/packages/core/test/linker/integration_spec.ts#L2253-L2265 https://github.com/angular/angular/blob/master/packages/core/test/linker/integration_spec.ts#L1252-L1263cyrilletuzi commentedon Feb 2, 2018
Setting a default value is not possible for objects, which is a very common case. Setting to
nulldoes not only require to set the| nullunion type, it also forces to add conditions checking if it's null or not for every bit of code using that data. So it's clearly not an option, especially when it's not relevant.The very classic architecture of Angular is : a controller component get data via a service and pass the data to a presentation component with
@Input(). Check is done in the controller component with*ngIf, so we know the@Input()won't benull, and it would be crazy to add conditions checking everywhere just because of TS behavior.So for me, it's sure it will be the option of not being
strict, which is sad. I think it's really weird TS introduced a feature which is not relevant/friendly with one of the bigger project using it (and I suppose Angular won't be the only affected framework/library). As I said in the other discussion, the current logic is "let's the developer change all his/her code (even when it's good code) to manage the problems", when it should be "let's TypeScript manage its own problems".nicolashenry commentedon Feb 2, 2018
@mhevery
@Attributeseems interesting in some situations, thanks :)Actually, I would have hoped that this (
@Inputon parameter property) :would be the equivalent to this in some way :
pgrm commentedon Feb 5, 2018
@cyrilletuzi - I don't think that any check forces you to set the input parameters, so technically marking them as potentially undefined does make sense. I'd rather want to have a possibility within angular to say - these properties need to be set, to have the type check there. The example above, by @nicolashenry would be perfect, if it works like that.
By the way - in case I don't care for implementing a setter for
myInputcouldn't I directly writemhevery commentedon Feb 5, 2018
@cyrilletuzi Nothing forces
@Input()to be set. A user of the your component may simply chose not to bind to that input in which case your@Input()is not initialize and you should have checks for non-initialized case. I know we disagree, but I think this is the correct behavior.What would be nice is to have
@Input({required:true})which would be an error if the user created your component and did not bind to that@Input, but as of yet we don't have such a feature.jbedard commentedon Feb 5, 2018
Could
@Input({required:true})not be accomplished just using ts somehow? By analyzing the@Inputvariable type and seeing ifundefinedis an acceptable type?cyrilletuzi commentedon Feb 5, 2018
What would be really nice is that
@Input()is required by default, except there is a default value. Like function parameters in TypeScript and quite any language.But with the actual behavior, yes, there should be a check, and there is one : the
*ngIfon the parent controller. So again, when checks are done and the code is good, it's not normal for the developer to have to add more TS specific code just to please TypeScript.22 remaining items
trotyl commentedon Feb 21, 2018
@cyrilletuzi The
strictPropertyInitializationoption cannot be applied to lib, there’s no such information (constructor implementation) exists to perform that check...kylecordes commentedon Mar 4, 2018
@trotyl I've had to make my way to that block of code in CLI before, to explain the Angular -> TypeScript supported versions. It seems to me that ideally this information would be represented canonically somewhere in Angular core (and then referred to by CLI code) as it seems to me this is inevitably a property of Angular itself that would apply even to non-CLI users. Roughly akin to the browser support information.
emilio-martinez commentedon Mar 5, 2018
Could not agree more, @kylecordes.
To that effect, I know that compiler feature landed somewhere in the road to 6.0 with 3ceee99. My assumption (without having tried it out myself) would be that as long as
ngccomplains loud enough, the CLI should just stop on its tracks if the TS version is unsupported, and developers can "opt out" to ignore viadisableTypeScriptVersionCheckin theangularCompilerOptions.angular-automatic-lock-bot commentedon Sep 13, 2019
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.