René's URL Explorer Experiment


Title: Different dependency injection behavior for abstract directives in Ivy · Issue #32981 · angular/angular · GitHub

Open Graph Title: Different dependency injection behavior for abstract directives in Ivy · Issue #32981 · angular/angular

X Title: Different dependency injection behavior for abstract directives in Ivy · Issue #32981 · angular/angular

Description: It looks like ngtsc behaves differently for abstract directives, compared to the behavior of ngc. Let's assume we have the following base class in our version 8 application: class ButtonBase { @ViewChild(...) ripple: MatRipple; // not us...

Open Graph Description: It looks like ngtsc behaves differently for abstract directives, compared to the behavior of ngc. Let's assume we have the following base class in our version 8 application: class ButtonBase { @Vie...

X Description: It looks like ngtsc behaves differently for abstract directives, compared to the behavior of ngc. Let's assume we have the following base class in our version 8 application: class ButtonBase { ...

Opengraph URL: https://github.com/angular/angular/issues/32981

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Different dependency injection behavior for abstract directives in Ivy","articleBody":"It looks like `ngtsc` behaves differently for abstract directives, compared to the behavior of `ngc`.\r\n\r\nLet's assume we have the following base class in our version 8 application:\r\n\r\n```ts\r\nclass ButtonBase {\r\n  @ViewChild(...) ripple: MatRipple;\r\n\r\n  // not using dependency injection.\r\n  constructor(animationMode: string)\r\n}\r\n```\r\n\r\nIn version 9 with Ivy, the `ButtonClass` needs to be decorated with `@Directive()` because `ButtonClass` declares a class member with an Angular decorator. This is part of our `@angular/core` migration for version 9. See [migration code](https://github.com/angular/angular/tree/master/packages/core/schematics/migrations/undecorated-classes-with-decorated-fields).\r\n\r\nAdding `@Directive()` here would be problematic because the `ButtonBase` class is never intended to be used in combination with dependency injection. i.e. the derived classes manually pass in the constructor parameters through a `super(..)` call. \r\n\r\nThe **problem** here is that `ngtsc` checks the constructor of `ButtonBase` now (since we added `@Directive`) and throws since it cannot find a suitable injection token for type `string`. The difference is that `ngc` does not seem to throw here. It seems to skip DI checking for abstract directives. Though `ngc` throws if some other non-abstract directive/ or component inherits the constructor from `ButtonBase`. This is reasonable.\r\n\r\n```\r\nNo suitable injection token for parameter 'noDiParameter' of class 'BaseDir'. Found string\r\n```\r\n\r\n\r\n\u003cdetails>\r\n\u003csummary>Here is a patch that can be used to reproduce this behavior in the Angular `compiler-cli` tests.\u003c/summary>\r\n\r\n```patch\r\ndiff --git a/packages/compiler-cli/test/ngc_spec.ts b/packages/compiler-cli/test/ngc_spec.ts\r\nindex 48bac17623..417f6eebda 100644\r\n--- a/packages/compiler-cli/test/ngc_spec.ts\r\n+++ b/packages/compiler-cli/test/ngc_spec.ts\r\n@@ -2287,7 +2287,7 @@ describe('ngc transformer command-line', () => {\r\n     expect(exitCode).toEqual(0);\r\n   });\r\n \r\n-  describe('base directives', () => {\r\n+  fdescribe('base directives', () => {\r\n     it('should allow directives with no selector that are not in NgModules', () => {\r\n       // first only generate .d.ts / .js / .metadata.json files\r\n       writeConfig(`{\r\n@@ -2297,9 +2297,13 @@ describe('ngc transformer command-line', () => {\r\n       write('main.ts', `\r\n           import {Directive} from '@angular/core';\r\n \r\n-          @Directive({})\r\n-          export class BaseDir {}\r\n-\r\n+          @Directive()\r\n+          export class BaseDir {\r\n+            // should not check DI parameters here. Derived classes can\r\n+            // manually pass a value to the superclass.\r\n+            constructor(noDiParameter: string) {}\r\n+          }\r\n+  \r\n           @Directive({})\r\n           export abstract class AbstractBaseDir {}\r\n \r\n@@ -2309,5 +2313,37 @@ describe('ngc transformer command-line', () => {\r\n       let exitCode = main(['-p', path.join(basePath, 'tsconfig.json')], errorSpy);\r\n       expect(exitCode).toEqual(0);\r\n     });\r\n+\r\n+    it('should check di when inheriting constructor from directive without selector', () => {\r\n+      // first only generate .d.ts / .js / .metadata.json files\r\n+      writeConfig(`{\r\n+          \"extends\": \"./tsconfig-base.json\",\r\n+          \"files\": [\"main.ts\"]\r\n+        }`);\r\n+      write('main.ts', `\r\n+          import {NgModule, Directive} from '@angular/core';\r\n+\r\n+          @Directive()\r\n+          export class BaseDir {\r\n+            constructor(noDiParameter: string) {}\r\n+          }\r\n+  \r\n+          @Directive({selector: 'greet'})\r\n+          export class GreetDir extends BaseDir {}\r\n+\r\n+          @NgModule({declarations: [GreetDir]})\r\n+          export class AppModule {}\r\n+      `);\r\n+\r\n+      // Stub the error spy because we don't want to call through and print the\r\n+      // expected error diagnostic.\r\n+      errorSpy.and.stub();\r\n+\r\n+      const exitCode = main(['-p', path.join(basePath, 'tsconfig.json')], errorSpy);\r\n+      expect(errorSpy).toHaveBeenCalledTimes(1);\r\n+      expect(errorSpy).toHaveBeenCalledWith(\r\n+          jasmine.stringMatching(/Can't resolve all parameters for GreetDir/));\r\n+      expect(exitCode).toEqual(1);\r\n+    });\r\n   });\r\n });\r\ndiff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts\r\nindex c94c751234..ce0ac89aa6 100644\r\n--- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts\r\n+++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts\r\n@@ -1022,12 +1022,16 @@ runInEachFileSystem(os => {\r\n         expect(jsContents).toContain('selectors: [[\"ng-component\"]]');\r\n       });\r\n \r\n-      it('should allow directives with no selector that are not in NgModules', () => {\r\n+      fit('should allow directives with no selector that are not in NgModules', () => {\r\n         env.write('main.ts', `\r\n           import {Directive} from '@angular/core';\r\n \r\n           @Directive({})\r\n-          export class BaseDir {}\r\n+          export class BaseDir {\r\n+            // should not check DI parameters here. Derived classes can\r\n+            // manually pass a value to the superclass.\r\n+            constructor(noDiParameter: string) {}\r\n+          }\r\n \r\n           @Directive({})\r\n           export abstract class AbstractBaseDir {}\r\n@@ -1044,6 +1048,27 @@ runInEachFileSystem(os => {\r\n         expect(errors.length).toBe(0);\r\n       });\r\n \r\n+      fit('should check di when inheriting constructor from directive without selector', () => {\r\n+        env.write('main.ts', `\r\n+          import {NgModule, Directive} from '@angular/core';\r\n+\r\n+          @Directive()\r\n+          export class BaseDir {\r\n+            constructor(noDiParameter: string) {}\r\n+          }\r\n+  \r\n+          @Directive({selector: 'greet'})\r\n+          export class GreetDir extends BaseDir {}\r\n+\r\n+          @NgModule({declarations: [GreetDir]})\r\n+          export class AppModule {}\r\n+        `);\r\n+        const errors = env.driveDiagnostics();\r\n+        expect(errors[0].messageText).toMatch(\r\n+            /No suitable injection token for parameter 'noDiParameter' of class 'BaseDir'/);\r\n+        expect(errors.length).toBe(1);\r\n+      });\r\n+\r\n       it('should not allow directives with no selector that are in NgModules', () => {\r\n         env.write('main.ts', `\r\n           import {Directive, NgModule} from '@angular/core';\r\n```\r\n\r\n\u003c/details>\r\n","author":{"url":"https://github.com/devversion","@type":"Person","name":"devversion"},"datePublished":"2019-10-03T13:11:08Z","url":"https://github.com/angular/angular/issues/32981"}

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/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:7e9e970a-7a75-3cb2-e281-b14a5f5a0e9e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEDB2:26ECEB:1A95BD9:21DE29A:6B0139FB
html-safe-nonce9b6b27e52f74b768738a6607d0569d6d5f1082e75d5b4755f882e5556cacfa5e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFREIyOjI2RUNFQjoxQTk1QkQ5OjIxREUyOUE6NkIwMTM5RkIiLCJ2aXNpdG9yX2lkIjoiMjA3NzAzNjcwMjg1MzA1MjkyMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacebe6da3ad283054fdbf8c902766c6c471325e9be36107218cea889ae6b1af319
hovercard-subject-tagissue:502057508
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/32981/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0279696fd270dc3dfacf88ec9be69fbab915d69a09b48b3913817dd2a5f0654a/angular/angular/issues/32981
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0279696fd270dc3dfacf88ec9be69fbab915d69a09b48b3913817dd2a5f0654a/angular/angular/issues/32981
og:image:altIt looks like ngtsc behaves differently for abstract directives, compared to the behavior of ngc. Let's assume we have the following base class in our version 8 application: class ButtonBase { @Vie...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedevversion
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular/issues/32981#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F32981
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%2Fissues%2F32981
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular
Reloadhttps://github.com/angular/angular/issues/32981
Reloadhttps://github.com/angular/angular/issues/32981
Reloadhttps://github.com/angular/angular/issues/32981
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues836 (836)https://github.com/angular/angular/issues
Pull requests141 (141)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
https://github.com/angular/angular
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/32981
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/32981
Different dependency injection behavior for abstract directives in Ivyhttps://github.com/angular/angular/issues/32981#top
https://github.com/JoostK
freq1: lowhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22freq1%3A%20low%22
hotlist: components teamRelated to Angular CDK or Angular Materialhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22hotlist%3A%20components%20team%22
state: has PRhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22state%3A%20has%20PR%22
type: bug/fixhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22type%3A%20bug%2Ffix%22
workaround4: nonehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22workaround4%3A%20none%22
Backloghttps://github.com/angular/angular/milestone/82
https://github.com/devversion
devversionhttps://github.com/devversion
on Oct 3, 2019https://github.com/angular/angular/issues/32981#issue-502057508
migration codehttps://github.com/angular/angular/tree/master/packages/core/schematics/migrations/undecorated-classes-with-decorated-fields
devversionhttps://github.com/devversion
comp: ivyhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22comp%3A%20ivy%22
on Oct 3, 2019https://github.com/angular/angular/issues/32981#event-2684006656
ngbothttps://github.com/apps/ngbot
needsTriagehttps://github.com/angular/angular/milestone/83
on Oct 3, 2019https://github.com/angular/angular/issues/32981#event-2684006707
devversionhttps://github.com/devversion
hotlist: components teamRelated to Angular CDK or Angular Materialhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22hotlist%3A%20components%20team%22
on Oct 3, 2019https://github.com/angular/angular/issues/32981#event-2684032374
JoostKhttps://github.com/JoostK
on Oct 3, 2019https://github.com/angular/angular/issues/32981#event-2685168000
JoostKhttps://github.com/JoostK
severity3: brokenhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22severity3%3A%20broken%22
state: has PRhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22state%3A%20has%20PR%22
type: bug/fixhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22type%3A%20bug%2Ffix%22
workaround4: nonehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22workaround4%3A%20none%22
freq1: lowhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22freq1%3A%20low%22
on Oct 3, 2019https://github.com/angular/angular/issues/32981#event-2685377727
ngbothttps://github.com/apps/ngbot
needsTriagehttps://github.com/angular/angular/milestone/83
Backloghttps://github.com/angular/angular/milestone/82
on Oct 3, 2019https://github.com/angular/angular/issues/32981#event-2685378498
https://github.com/alxhub
alxhubhttps://github.com/alxhub
on Oct 10, 2019https://github.com/angular/angular/issues/32981#issuecomment-540829372
@JoostKhttps://github.com/JoostK
AndrewKushnirhttps://github.com/AndrewKushnir
completedhttps://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
8d15bfahttps://github.com/angular/angular/commit/8d15bfa6eebad42652855f65a2d660af5d273925
on Oct 25, 2019https://github.com/angular/angular/issues/32981#event-2745206840
https://github.com/apps/angular-automatic-lock-bot
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Nov 25, 2019https://github.com/angular/angular/issues/32981#issuecomment-558225713
automatic conversation locking policyhttps://github.com/angular/angular/blob/67d80f/docs/GITHUB_PROCESS.md#conversation-locking
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Nov 25, 2019https://github.com/angular/angular/issues/32981#event-2828711533
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/32981
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/32981
JoostKhttps://github.com/JoostK
freq1: lowhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22freq1%3A%20low%22
hotlist: components teamRelated to Angular CDK or Angular Materialhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22hotlist%3A%20components%20team%22
state: has PRhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22state%3A%20has%20PR%22
type: bug/fixhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22type%3A%20bug%2Ffix%22
workaround4: nonehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22workaround4%3A%20none%22
BacklogNo due datehttps://github.com/angular/angular/milestone/82
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.