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

Feature Request: Allow Non-Blocking Mode for strictTemplates #55868

Closed
tomer953 opened this issue May 18, 2024 · 6 comments
Closed

Feature Request: Allow Non-Blocking Mode for strictTemplates #55868

tomer953 opened this issue May 18, 2024 · 6 comments
Assignees
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: template type-checking
Milestone

Comments

@tomer953
Copy link

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

@tomer953
Copy link
Author

related to: angular/vscode-ng-language-service#1646

Seems like VSCode extension allow to force strictTemplates without effecting the build process, However:

  • its only works with VSCode, other IDEs don't have this flag
  • Its an optional choice by the developer, and can't be enforced by a project setting.

@JoostK
Copy link
Member

JoostK commented May 20, 2024

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.

@spock123
Copy link

spock123 commented May 20, 2024

@JoostK We're in the same boat as @tomer953 and feel quite stupid not having thought of this solution... thanks!

@tomer953
Copy link
Author

tomer953 commented May 20, 2024

Edited:

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

🚀

@pkozlowski-opensource pkozlowski-opensource added area: compiler Issues related to `ngc`, Angular's template compiler compiler: template type-checking labels May 22, 2024
@ngbot ngbot bot modified the milestone: needsTriage May 22, 2024
@tomer953
Copy link
Author

tomer953 commented May 23, 2024

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.

@alxhub
Copy link
Member

alxhub commented 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:

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

  1. Angular already has incremental ratcheting flags for type-checking strictness.

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

@alxhub alxhub closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: template type-checking
Projects
None yet
Development

No branches or pull requests

5 participants