Fix Strict Templates
Documentation for Developers
Fix Angular strictTemplates warnings and errors
What this solves
When Angular Language Service shows “Some language features are not available. Enable strictTemplates…”, strict template type checking isn’t enabled in one or more tsconfig.*.json files.
Enable strict templates
Add the following to all relevant configs that the project/app or library uses:
Recommended locations:
- Root
tsconfig.json - App:
tsconfig.app.json - Libs:
tsconfig.lib.json(andtsconfig.lib.prod.jsonif present) - Tests:
tsconfig.spec.json
Use these options:
"angularCompilerOptions": {
"strictTemplates": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true
}
- For buildable libraries keep:
"compilationMode": "partial". - Remove or update any overrides setting these back to
falsein extended configs (e.g.,tsconfig.base.json).
Restart language services
- VS Code → Cmd+Shift+P → “TypeScript: Restart TS Server”
- Also restart Angular Language Service or reload the window
Common fixes after enabling strict mode
- Inputs/Outputs must be explicitly typed; avoid
any. - Guard nullable values or use safe navigation in templates:
user?.name. - Move logic out of templates into
computed()signals and bind the computed value. - In
@for, always provide a track strategy:@for (item of items; track item.id) { ... }. - Event handlers should have correct types (e.g.,
onClick(event: MouseEvent)). - Keep aliases resolvable where used (example for docs app):
"compilerOptions": {
"paths": {
"@environment": ["../../environments/environment.ts"]
}
}
Troubleshooting
- Search the repo for
strictTemplates": falseand flip any remaining occurrences. - Ensure the config you edited is actually referenced by the app/library
tsconfig.jsonviareferences/extends. - Re-run build/lint to catch any remaining template type issues early.