Skip to content

TypeScript 2.7 support #21571

Closed
Closed

Description

@IgorMinar

TypeScript 2.7 is coming out in January. We need to get it supported within the v6 timeframe.

Activity

  1. added this to the milestone on Jan 16, 2018
  2. cyrilletuzi commented on Jan 23, 2018

    @cyrilletuzi
    Contributor

    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.

    What's the plans about that ?

  3. IgorMinar commented on Jan 23, 2018

    @IgorMinar
    ContributorAuthor
  4. added
    featureLabel used to distinguish feature request from other issues
    area: coreIssues related to the framework runtime
    on Jan 23, 2018
  5. IgorMinar commented on Feb 2, 2018

    @IgorMinar
    ContributorAuthor

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

  6. nicolashenry commented on Feb 2, 2018

    @nicolashenry

    @IgorMinar

    Why can not inputs be defined in the constructor? Like this for example :

    @Component({ selector: 'my-component' })
    class MyComponent {
        constructor(@Input() private myInput: string) {}
    }

    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.

  7. mhevery commented on Feb 2, 2018

    @mhevery
    Contributor

    Inputs by definition can change over time. Constructor can only receive one value. But you can use @Attribute in 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-L1263

  8. cyrilletuzi commented on Feb 2, 2018

    @cyrilletuzi
    Contributor

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

  9. nicolashenry commented on Feb 2, 2018

    @nicolashenry

    @mhevery @Attribute seems interesting in some situations, thanks :)

    Actually, I would have hoped that this (@Input on parameter property) :

    @Component({ selector: 'my-component' })
    class MyComponent {
        constructor(@Input('myInput') public myInput: string) {}
    }

    would be the equivalent to this in some way :

    @Component({ selector: 'my-component' })
    class MyComponent {
        @Input('myInput')
        public myInput: string;
        constructor(@Attribute('myInput') myInput: string) {
            this.myInput = myInput;
        }
    }
  10. pgrm commented on Feb 5, 2018

    @pgrm

    @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) { }
    }
    
  11. mhevery commented on Feb 5, 2018

    @mhevery
    Contributor

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

  12. jbedard commented on Feb 5, 2018

    @jbedard
    Contributor

    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?

  13. cyrilletuzi commented on Feb 5, 2018

    @cyrilletuzi
    Contributor

    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.

  14. 22 remaining items

  15. trotyl commented on Feb 21, 2018

    @trotyl
    Contributor

    @cyrilletuzi The strictPropertyInitialization option cannot be applied to lib, there’s no such information (constructor implementation) exists to perform that check...

  16. kylecordes commented on Mar 4, 2018

    @kylecordes

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

  17. emilio-martinez commented on Mar 5, 2018

    @emilio-martinez
    Contributor

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

  18. angular-automatic-lock-bot commented on Sep 13, 2019

    @angular-automatic-lock-bot

    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.

  19. locked and limited conversation to collaborators on Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimefeatureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions