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
{{ message }}
Repository navigation
Feature Request: Allow Non-Blocking Mode for strictTemplates #55868
Which @angular/* package(s) are relevant/related to the feature request?
language-service
Description
We are working on a large-scale Angular project and are interested in adopting the strictTemplates option to improve our type safety and overall code quality. However, enabling strictTemplates currently flags a significant number of errors due to our existing codebase size, making an immediate adoption impractical as it would halt our build processes.
Proposed solution
Implement an option within angularCompilerOptions where strictTemplates can be enabled in a non-blocking mode. This mode would allow developers to see warnings instead of errors for strict template checks, preventing them from blocking the build process. This feature would be incredibly beneficial for large projects wanting to gradually adopt strict type checking in their templates without disrupting their development workflow.
Alternatives considered
Incremental Adoption \ Directive/Component Specific Flagging
I'd recommend to adopt different tsconfig.json files for this pattern. I suspect that IDEs typically use the closest tsconfig.json, so having a tsconfig.app.json which extends the base tsconfig would allow you to have different compiler options for builds vs IDE.
Oh got it.. so its actually pretty simple just use different tsconfig file for the tsConfig option in the angular.json and let the IDE use the default tsconfig file for template checks
The workaround is not the easiest on large projects, We had to change every tsConfig build path in the angular.json and create new tsconfig files for each project
I hope we will have some option to force strict template option on the language service, so I'll keep this issue open.
We've discussed this question and decided that we shouldn't try to support any kind of warning mode for strictTemplates, for a few significant reasons:
tsconfig.json is already a standard way of applying different configurations to different parts of your codebase.
This is how TypeScript rolls out new strictness flags - at the granularity of the tsconfig options. It's also possible to configure two tsconfig.jsons: one for the actual build, and one which enables new flags for experimentation.
The way template type-checking works really isn't conducive to lifting specific types of checks into warnings.
Template type-checking works by generating TypeScript code representing the template, and feeding it to TypeScript's checker. The diagnostics we get back are (for the most part) real TypeScript diagnostics produced by tsc. Therefore we can't really know per-diagnostic why it was produced, only that TypeScript found something wrong in the template block. Sometimes we can correlate specific lines with specific types of checks, but mostly this is not the case.
Activity
tomer953 commentedon May 18, 2024
related to: angular/vscode-ng-language-service#1646
Seems like VSCode extension allow to force strictTemplates without effecting the build process, However:
JoostK commentedon May 20, 2024
I'd recommend to adopt different
tsconfig.jsonfiles for this pattern. I suspect that IDEs typically use the closesttsconfig.json, so having atsconfig.app.jsonwhich extends the basetsconfigwould allow you to have different compiler options for builds vs IDE.spock123 commentedon May 20, 2024
@JoostK We're in the same boat as @tomer953 and feel quite stupid not having thought of this solution... thanks!
tomer953 commentedon May 20, 2024
Edited:
Oh got it.. so its actually pretty simple just use different tsconfig file for the
tsConfigoption in theangular.jsonand let the IDE use the defaulttsconfigfile for template checks🚀
tomer953 commentedon May 23, 2024
The workaround is not the easiest on large projects, We had to change every
tsConfigbuild path in theangular.jsonand create newtsconfigfiles for each projectI hope we will have some option to force strict template option on the language service, so I'll keep this issue open.
alxhub commentedon May 29, 2024
We've discussed this question and decided that we shouldn't try to support any kind of warning mode for
strictTemplates, for a few significant reasons:tsconfig.jsonis already a standard way of applying different configurations to different parts of your codebase.This is how TypeScript rolls out new strictness flags - at the granularity of the tsconfig options. It's also possible to configure two
tsconfig.jsons: one for the actual build, and one which enables new flags for experimentation.Angular already has incremental ratcheting flags for type-checking strictness.
The way template type-checking works really isn't conducive to lifting specific types of checks into warnings.
Template type-checking works by generating TypeScript code representing the template, and feeding it to TypeScript's checker. The diagnostics we get back are (for the most part) real TypeScript diagnostics produced by
tsc. Therefore we can't really know per-diagnostic why it was produced, only that TypeScript found something wrong in the template block. Sometimes we can correlate specific lines with specific types of checks, but mostly this is not the case.angular-automatic-lock-bot commentedon Jun 29, 2024
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.