René's URL Explorer Experiment


Title: feat(compiler): narrow types of expressions used in *ngIf by chuckjaz · Pull Request #20702 · angular/angular · GitHub

Open Graph Title: feat(compiler): narrow types of expressions used in *ngIf by chuckjaz · Pull Request #20702 · angular/angular

X Title: feat(compiler): narrow types of expressions used in *ngIf by chuckjaz · Pull Request #20702 · angular/angular

Description: Structural directives can now specify a type guard that describes what types can be inferred for an input expression inside the directive's template. NgIf was modified to declare an input guard on ngIf. After this change, fullTemplateTypeCheck will infer that usage of ngIf expression inside it's template is truthy. For example, if a component has a property person?: Person and a template of

{{person.name}}
the compiler will no longer report that person might be null or undefined. The template compiler will generate code similar to, if (NgIf.ngIfTypeGuard(instance.person)) { instance.person.name } to validate the template's use of the interpolation expression. Calling the type guard in this fashion allows TypeScript to infer that person is non-null. PR Type What kind of change does this PR introduce? [x] Feature What is the current behavior? Given a component like: export interface Person { name: string; } @Component({ template: `
Hello {{person.name}}
` }) export Greeter { @Input() person?: Person; } The compiler would produce an error stating that person might be undefined. What is the new behavior? The compiler infers that person is Person inside the *ngIfbut is still Person | undefined outside the *ngIf. Does this PR introduce a breaking change? [ ] Yes [ ] No Other information

Open Graph Description: Structural directives can now specify a type guard that describes what types can be inferred for an input expression inside the directive's template. NgIf was modified to declare an input guard...

X Description: Structural directives can now specify a type guard that describes what types can be inferred for an input expression inside the directive's template. NgIf was modified to declare an input g...

Opengraph URL: https://github.com/angular/angular/pull/20702

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:88cb2b65-6571-2155-7e6f-c34077eafebb
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idC95A:E0ADF:D9BE74:11394C4:6B01ED18
html-safe-noncee3afa2c5dcd33de3b439a00313c0e76e7d6d82cf66f9fcf080d77ec7613a2381
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOTVBOkUwQURGOkQ5QkU3NDoxMTM5NEM0OjZCMDFFRDE4IiwidmlzaXRvcl9pZCI6IjQ5NzY5MzA1NzE2NTA0NjA5NTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac01f7421d2efcf28a1ec43c2d9940e213c1df45aef378f3afcb2d6295e0ae1a73
hovercard-subject-tagpull_request:155494695
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/angular/angular/pull/20702/files
twitter:imagehttps://avatars.githubusercontent.com/u/372013?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/372013?s=400&v=4
og:image:altStructural directives can now specify a type guard that describes what types can be inferred for an input expression inside the directive's template. NgIf was modified to declare an input guard...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/angular/angular git https://github.com/angular/angular.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id24195339
octolytics-dimension-repository_nwoangular/angular
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24195339
octolytics-dimension-repository_network_root_nwoangular/angular
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/angular/angular/pull/20702/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fpull%2F20702%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fpull%2F20702%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=angular%2Fangular
Reloadhttps://github.com/angular/angular/pull/20702/files
Reloadhttps://github.com/angular/angular/pull/20702/files
Reloadhttps://github.com/angular/angular/pull/20702/files
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues835 (835)https://github.com/angular/angular/issues
Pull requests142 (142)https://github.com/angular/angular/pulls
Discussionshttps://github.com/angular/angular/discussions
Actionshttps://github.com/angular/angular/actions
Projectshttps://github.com/angular/angular/projects
Security and quality40 (40)https://github.com/angular/angular/security
Insightshttps://github.com/angular/angular/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fangular%2Fangular%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fangular%2Fangular%2Fissues%2Fnew%2Fchoose
chuckjazhttps://github.com/chuckjaz
angular:masterhttps://github.com/angular/angular/tree/master
chuckjaz:type-narrowhttps://github.com/chuckjaz/angular/tree/type-narrow
Conversation 22 https://github.com/angular/angular/pull/20702
Commits 1 https://github.com/angular/angular/pull/20702/commits
Checks 0 https://github.com/angular/angular/pull/20702/checks
Files changed https://github.com/angular/angular/pull/20702/files
Please reload this pagehttps://github.com/angular/angular/pull/20702/files
feat(compiler): narrow types of expressions used in *ngIf https://github.com/angular/angular/pull/20702/files#top
Show all changes 1 commit https://github.com/angular/angular/pull/20702/files
4c47bc4 feat(compiler): narrow types of expressions used in *ngIf chuckjaz Nov 30, 2017 https://github.com/angular/angular/pull/20702/commits/4c47bc431e2e372e6c08ad4f336db76906c3ad63
Clear filters https://github.com/angular/angular/pull/20702/files
Please reload this pagehttps://github.com/angular/angular/pull/20702/files
Please reload this pagehttps://github.com/angular/angular/pull/20702/files
ng_if.ts https://github.com/angular/angular/pull/20702/files#diff-bc2a64986fd7bb7d2e6c22feeb7f835260695b17224408fc7f4d824441f53abd
check_types_spec.ts https://github.com/angular/angular/pull/20702/files#diff-8576cf2cb8c40dd3e4ae3914c55ba1e0a2ca2616d3ca63a6da90ccdb126e9123
collector_spec.ts https://github.com/angular/angular/pull/20702/files#diff-5504cc717b0668e556404e2f3b63e451ef939d6eff7cfbf90f9e78eafc617428
compiler.ts https://github.com/angular/angular/pull/20702/files#diff-2277240aed9253b2c744300f76a4e7222a79a5dcbd3497611e10d7f93e016a9e
static_reflector.ts https://github.com/angular/angular/pull/20702/files#diff-8d77cc7e48aeb2df183f57f41bff57d3014b18ae89f9d39a3dc0b469237a01b4
compile_metadata.ts https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
compile_reflector.ts https://github.com/angular/angular/pull/20702/files#diff-5aeea9b1f10b594c499d979da86bf3ed706a30e21e9b30ded42a9a93961a0490
expression_converter.ts https://github.com/angular/angular/pull/20702/files#diff-90361fe3df79fa539acec02d1812a9564d9ff27983fee077f398b69a525fafab
core.ts https://github.com/angular/angular/pull/20702/files#diff-e713b14df487f1e1948f4c54c98e8142c15406094ff4ee2a6a89f1a3d06fd153
directive_resolver.ts https://github.com/angular/angular/pull/20702/files#diff-8e41cb8514686ca6fc3221fb3fcf4b6c93b6cc6f28fbcec596dc8e517b632339
metadata_resolver.ts https://github.com/angular/angular/pull/20702/files#diff-b9378a5d61f2c7bb112d43c3ac35c824658486c08a89021e9bef221a0f0288e5
type_check_compiler.ts https://github.com/angular/angular/pull/20702/files#diff-966b1b6f96a8480836f8e42ce99e4e5f5315c3621e38b46c866fa9290d89bc40
view_compiler.ts https://github.com/angular/angular/pull/20702/files#diff-c38b9fae86411e5e337f121379649435b34f0478d0cb50676054a19cbd2daf04
directive_resolver_spec.ts https://github.com/angular/angular/pull/20702/files#diff-b4354d131f30d9e366b21abf93970d39918da35b8141021ab84eac0e2ff393cf
template_parser_spec.ts https://github.com/angular/angular/pull/20702/files#diff-67ed5e19f812813cc28265f5cb60074bad4e1cf626330eabfdbd6597d6a78190
platform_reflection_capabilities.ts https://github.com/angular/angular/pull/20702/files#diff-0581c00fd6fcdff68bbe0c13b298416a6da356094bf95edeae92b682715ebda1
reflection_capabilities.ts https://github.com/angular/angular/pull/20702/files#diff-8c5fb745169ff0eb724e95f6b54f3b842663c76f1abbd222fe13a3171f031242
compiler_reflector.ts https://github.com/angular/angular/pull/20702/files#diff-f180fa64953c203cc598d70a4541ed529b0070c6e8bbb2f74a8b2808248bae1b
common.d.ts https://github.com/angular/angular/pull/20702/files#diff-8f04e04e51db03a1fa86550e492017d75859c13236cac866e8727c788a843710
packages/common/src/directives/ng_if.tshttps://github.com/angular/angular/pull/20702/files#diff-bc2a64986fd7bb7d2e6c22feeb7f835260695b17224408fc7f4d824441f53abd
View file https://github.com/chuckjaz/angular/blob/4c47bc431e2e372e6c08ad4f336db76906c3ad63/packages/common/src/directives/ng_if.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/angular/angular/pull/20702/{{ revealButtonHref }}
https://github.com/angular/angular/pull/20702/files#diff-bc2a64986fd7bb7d2e6c22feeb7f835260695b17224408fc7f4d824441f53abd
https://github.com/angular/angular/pull/20702/files#diff-bc2a64986fd7bb7d2e6c22feeb7f835260695b17224408fc7f4d824441f53abd
packages/compiler-cli/test/diagnostics/check_types_spec.tshttps://github.com/angular/angular/pull/20702/files#diff-8576cf2cb8c40dd3e4ae3914c55ba1e0a2ca2616d3ca63a6da90ccdb126e9123
View file https://github.com/chuckjaz/angular/blob/4c47bc431e2e372e6c08ad4f336db76906c3ad63/packages/compiler-cli/test/diagnostics/check_types_spec.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/angular/angular/pull/20702/{{ revealButtonHref }}
https://github.com/angular/angular/pull/20702/files#diff-8576cf2cb8c40dd3e4ae3914c55ba1e0a2ca2616d3ca63a6da90ccdb126e9123
https://github.com/angular/angular/pull/20702/files#diff-8576cf2cb8c40dd3e4ae3914c55ba1e0a2ca2616d3ca63a6da90ccdb126e9123
packages/compiler-cli/test/metadata/collector_spec.tshttps://github.com/angular/angular/pull/20702/files#diff-5504cc717b0668e556404e2f3b63e451ef939d6eff7cfbf90f9e78eafc617428
View file https://github.com/chuckjaz/angular/blob/4c47bc431e2e372e6c08ad4f336db76906c3ad63/packages/compiler-cli/test/metadata/collector_spec.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/angular/angular/pull/20702/{{ revealButtonHref }}
https://github.com/angular/angular/pull/20702/files#diff-5504cc717b0668e556404e2f3b63e451ef939d6eff7cfbf90f9e78eafc617428
https://github.com/angular/angular/pull/20702/files#diff-5504cc717b0668e556404e2f3b63e451ef939d6eff7cfbf90f9e78eafc617428
packages/compiler/src/aot/compiler.tshttps://github.com/angular/angular/pull/20702/files#diff-2277240aed9253b2c744300f76a4e7222a79a5dcbd3497611e10d7f93e016a9e
View file https://github.com/chuckjaz/angular/blob/4c47bc431e2e372e6c08ad4f336db76906c3ad63/packages/compiler/src/aot/compiler.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/angular/angular/pull/20702/{{ revealButtonHref }}
https://github.com/angular/angular/pull/20702/files#diff-2277240aed9253b2c744300f76a4e7222a79a5dcbd3497611e10d7f93e016a9e
https://github.com/angular/angular/pull/20702/files#diff-2277240aed9253b2c744300f76a4e7222a79a5dcbd3497611e10d7f93e016a9e
packages/compiler/src/aot/static_reflector.tshttps://github.com/angular/angular/pull/20702/files#diff-8d77cc7e48aeb2df183f57f41bff57d3014b18ae89f9d39a3dc0b469237a01b4
View file https://github.com/chuckjaz/angular/blob/4c47bc431e2e372e6c08ad4f336db76906c3ad63/packages/compiler/src/aot/static_reflector.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/angular/angular/pull/20702/{{ revealButtonHref }}
https://github.com/angular/angular/pull/20702/files#diff-8d77cc7e48aeb2df183f57f41bff57d3014b18ae89f9d39a3dc0b469237a01b4
https://github.com/angular/angular/pull/20702/files#diff-8d77cc7e48aeb2df183f57f41bff57d3014b18ae89f9d39a3dc0b469237a01b4
https://github.com/angular/angular/pull/20702/files#diff-8d77cc7e48aeb2df183f57f41bff57d3014b18ae89f9d39a3dc0b469237a01b4
https://github.com/angular/angular/pull/20702/files#diff-8d77cc7e48aeb2df183f57f41bff57d3014b18ae89f9d39a3dc0b469237a01b4
https://github.com/angular/angular/pull/20702/files#diff-8d77cc7e48aeb2df183f57f41bff57d3014b18ae89f9d39a3dc0b469237a01b4
https://github.com/angular/angular/pull/20702/files#diff-8d77cc7e48aeb2df183f57f41bff57d3014b18ae89f9d39a3dc0b469237a01b4
packages/compiler/src/compile_metadata.tshttps://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
View file https://github.com/chuckjaz/angular/blob/4c47bc431e2e372e6c08ad4f336db76906c3ad63/packages/compiler/src/compile_metadata.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/angular/angular/pull/20702/{{ revealButtonHref }}
https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
https://github.com/angular/angular/pull/20702/files#diff-8f896d2b8af5e780928fed8da3c434d42e5315aecef11726b606cfcd1c007176
packages/compiler/src/compile_reflector.tshttps://github.com/angular/angular/pull/20702/files#diff-5aeea9b1f10b594c499d979da86bf3ed706a30e21e9b30ded42a9a93961a0490
View file https://github.com/chuckjaz/angular/blob/4c47bc431e2e372e6c08ad4f336db76906c3ad63/packages/compiler/src/compile_reflector.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/angular/angular/pull/20702/{{ revealButtonHref }}
https://github.com/angular/angular/pull/20702/files#diff-5aeea9b1f10b594c499d979da86bf3ed706a30e21e9b30ded42a9a93961a0490
packages/compiler/src/compiler_util/expression_converter.tshttps://github.com/angular/angular/pull/20702/files#diff-90361fe3df79fa539acec02d1812a9564d9ff27983fee077f398b69a525fafab
View file https://github.com/chuckjaz/angular/blob/4c47bc431e2e372e6c08ad4f336db76906c3ad63/packages/compiler/src/compiler_util/expression_converter.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/angular/angular/pull/20702/{{ revealButtonHref }}
https://github.com/angular/angular/pull/20702/files#diff-90361fe3df79fa539acec02d1812a9564d9ff27983fee077f398b69a525fafab
https://github.com/angular/angular/pull/20702/files#diff-90361fe3df79fa539acec02d1812a9564d9ff27983fee077f398b69a525fafab
https://github.com/angular/angular/pull/20702/files#diff-90361fe3df79fa539acec02d1812a9564d9ff27983fee077f398b69a525fafab
packages/compiler/src/core.tshttps://github.com/angular/angular/pull/20702/files#diff-e713b14df487f1e1948f4c54c98e8142c15406094ff4ee2a6a89f1a3d06fd153
View file https://github.com/chuckjaz/angular/blob/4c47bc431e2e372e6c08ad4f336db76906c3ad63/packages/compiler/src/core.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/angular/angular/pull/20702/{{ revealButtonHref }}
https://github.com/angular/angular/pull/20702/files#diff-e713b14df487f1e1948f4c54c98e8142c15406094ff4ee2a6a89f1a3d06fd153
https://github.com/angular/angular/pull/20702/files#diff-e713b14df487f1e1948f4c54c98e8142c15406094ff4ee2a6a89f1a3d06fd153
Please reload this pagehttps://github.com/angular/angular/pull/20702/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.