-
Notifications
You must be signed in to change notification settings - Fork 12k
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
feat(@schematics/angular): add strict
compiler option to workspace tsconfig
#14905
Conversation
This needs more discussion. I want to understand the impact and also why the app specific tsconfig has no strictness flags set. |
From a review of similar tools, the following all set This change would also only affect newly created projects. |
|
We need to check with our AIO examples if they even work with these options. Some of them are also problematic on their own, like |
class C {
@Input() readonly foo!: number;
// ^
// Notice this '!' modifier.
// This is the "definite assignment assertion"
} If you need more help about strict type check, I am happy to help. By the way, I think we should use more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking this as requiring change just to move it off the Approved reviews list.
What do I need to do to get this PR merged? |
@xiaoxiangmoe - On our side we need to turn one flag at a time in our documentation projects to make sure all our documentation works with each of these flags. And then enable it in the CLI by default. For example adding a "!" is not acceptable without changing our documentation to reflect something like that(and I don't know whether it's a good idea to make everyone do that) |
I just had a look at this, and it seems that AIO is already in I have updated this PR to reflect the AIO settings. |
@alan-agius4 can we enable strictPropertyInitialization in angular 9? |
@xiaoxiangmoe, while I cannot say for certain. I highly doubt that we would be able to enable |
@alan-agius4 Maybe we can provide some instructions in the documentation -- what do we need to do if we want to enable |
Hi @xiaoxiangmoe, fyi there is an issue in angular/angular related to |
The feedback from Angular team on latest proposal -
|
This End users should fully embrace the |
Blocked until we get a list of which options we should to enable by default. @vikerman will checks the order of option that were enabling in G3 and we’ll decide based on that. |
The current list which we think is basic for most samples/examples in the wild and also our ecosystem is
|
I really like the idea of having a I would really prefer to make this Perhaps strict mode that defaults to |
I'd also like to have these settings tested against projects generated using all of the Angular Material Schematics and the material.angular.io docs project (and yes, I recognize that this change would only directly impact newly created projects). |
"strict": { | ||
"description": "Creates a workspace with stricter TypeScript compiler options.", | ||
"type": "boolean", | ||
"default": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably set this to false
and get the PR in. And move the decision on whether we want to turn in on for 9.0 based on data we collect for this, later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "noImplicitAny": true,
should be there regardless of the setting. Without it, a developer is essentially bypassing the overwhelming majority of the benefits of TypeScript and may not actually realize it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess just adding a new flag is not enough to get noticed by developers. It may be better to make a prompt like "Would you like to enable TypeScript strict type checking? (y/N)". And I agree on the false
by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for sure we should
- Turn off by default, add prompt so that it's more discoverable by users
- We revisit this based on the feedback we get right before version 9 RC.
The actual Angular material samples tsconfig is here and already using here - https://github.com/angular/components/blob/cf70c4342e7ea277011cf289e721383b7784a18a/src/material-examples/tsconfig-build.json We will look into what tests we have around testing Material schematics. Thanks. |
Glad to see the examples using that. I enabled these checks in material.angular.io's tsconfig and I'm seeing about 30 errors. Half of them are due to It's not the end of the world and I can try to put together a PR to fix this, but it's an indication that people will certainly hit this. I guess the hope is that it will encourage them to write cleaner code, but I think that there will certainly be issues with tutorials, guides, blog posts, and other material that "won't work" in the default Angular CLI after strict becomes enabled by default. |
This is only for new projects. So we do fully expect existing projects to break when users manually switch the strict flags. We need to find a way to get all course creators to ensure that if they create a project created from scratch their code works with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's a prompt now, I think it would be clearer to just use the actual TS strict
option. I think it will be confusing that stricter type checking is not actually strict as is the case for other frameworks.
align with the examples and the new CLI settings by enabling - `noImplicitAny` - `noImplicitReturns` - `noImplicitThis` - `noFallthroughCasesInSwitch` - `strictNullChecks` Relates to angular/angular-cli#14905
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Maybe we can consider providing |
The current plan is to slowly move to a more strict configuration over the next set of versions. This is to ensure that both first and third party documentation, training material, courseware, etc. are adequately prepared for the changes. |
Is there an associated GitHub or JIRA issue for verifying that all examples on AIO compile with the stricter flags? For verifying that CLI, PWA, and Universal Schematics generate code that compiles with the new flags? I've opened angular/components#17135 to track this for the Angular Material Schematics. |
align with the examples and the new CLI settings by enabling - `noImplicitAny` - `noImplicitReturns` - `noImplicitThis` - `noFallthroughCasesInSwitch` - `strictNullChecks` Relates to angular/angular-cli#14905
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Add "stricter" compiler option to workspace tsconfig
Closes #14694