Skip to content
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

schematics: verify that generated code passes CLI's stricter compiler flags #17135

Closed
Splaktar opened this issue Sep 18, 2019 · 3 comments · Fixed by #17159
Closed

schematics: verify that generated code passes CLI's stricter compiler flags #17135

Splaktar opened this issue Sep 18, 2019 · 3 comments · Fixed by #17159
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@Splaktar
Copy link
Member

Splaktar commented Sep 18, 2019

Reproduction

PR angular/angular-cli#14905 introduces a new strict option to the Angular CLI. This option is currently false by default, but there are plans to make it true in version 9 or 10.

    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noFallthroughCasesInSwitch": true,
    "strictNullChecks": true,

Expected Behavior

We need to make sure that all of the code generated by our Schematics will compile with these new flags.

We already use these flags for building the library source and examples.

PR angular/material.angular.io#631 adds these compiler flags for material.angular.io builds as well.

Related Issues

I'm not sure if this is something that we can do in integration tests (#16479) or not. But it seems possible and would be needed to avoid introducing regressions over time.

#13329 tracks making the library code follow even stricter checks (--strictPropertyInitialization).

#16028 relates to stricter template checks in Ivy.

@clydin
Copy link
Member

clydin commented Sep 19, 2019

The following should be the current ideal settings (AIO is currently using them) to test against as this will likely be the eventual final state of the CLI's defaults. Note also that many users will enable strict settings as their first step after creating a new project; so ensuring the schematics work in this scenario would also be useful.

"strict": true
"strictPropertyInitialization": false

@Splaktar
Copy link
Member Author

I'm currently seeing the following compilation errors after enabling these stricter settings in a project that just has Angular Material Schematics in it.

ERROR in app/table/table-datasource.ts:107:18 - error TS7006: Parameter 'a' implicitly has an 'any' type.

107 function compare(a, b, isAsc) {
                     ~
app/table/table-datasource.ts:107:21 - error TS7006: Parameter 'b' implicitly has an 'any' type.

107 function compare(a, b, isAsc) {
                        ~
app/table/table-datasource.ts:107:24 - error TS7006: Parameter 'isAsc' implicitly has an 'any' type.

107 function compare(a, b, isAsc) {
                           ~~~~~
app/tree/tree.component.ts:46:7 - error TS2345: Argument of type '(node: FileNode) => Observable<FileNode[] | undefined>' is not assignable to parameter of type '(node: FileNode) => FileNode[] | Observable<FileNode[]> | null | undefined'.
  Type 'Observable<FileNode[] | undefined>' is not assignable to type 'FileNode[] | Observable<FileNode[]> | null | undefined'.
    Type 'Observable<FileNode[] | undefined>' is not assignable to type 'Observable<FileNode[]>'.
      Type 'FileNode[] | undefined' is not assignable to type 'FileNode[]'.
        Type 'undefined' is not assignable to type 'FileNode[]'.

46       this.getChildren);
         ~~~~~~~~~~~~~~~~

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants