angular/packages
JoostK bc54687c7b fix(compiler-cli): exclude abstract classes from strictInjectionParameters requirement (#44615)
In AOT compilations, the `strictInjectionParameters` compiler option can
be enabled to report errors when an `@Injectable` annotated class has a
constructor with parameters that do not provide an injection token, e.g.
only a primitive type or interface.

Since Ivy it's become required that any class with Angular behavior
(e.g. the `ngOnDestroy` lifecycle hook) is decorated using an Angular
decorator, which meant that `@Injectable()` may need to have been added
to abstract base classes. Doing so would then report an error if
`strictInjectionParameters` is enabled, if the abstract class has an
incompatible constructor for DI purposes. This may be fine though, as
a subclass may call the constructor explicitly without relying on
Angular's DI mechanism.

Therefore, this commit excludes abstract classes from the
`strictInjectionParameters` check. This avoids an error from being
reported at compile time. If the constructor ends up being used by
Angular's DI system at runtime, then the factory function of the
abstract class will throw an error by means of the `ɵɵinvalidFactory`
instruction.

In addition to the runtime error, this commit also analyzes the inheritance
chain of an injectable without a constructor to verify that their inherited
constructor is valid.

BREAKING CHANGE: Invalid constructors for DI may now report compilation errors

When a class inherits its constructor from a base class, the compiler may now
report an error when that constructor cannot be used for DI purposes. This may
either be because the base class is missing an Angular decorator such as
`@Injectable()` or `@Directive()`, or because the constructor contains parameters
which do not have an associated token (such as primitive types like `string`).
These situations used to behave unexpectedly at runtime, where the class may be
constructed without any of its constructor parameters, so this is now reported
as an error during compilation.

Any new errors that may be reported because of this change can be resolved either
by decorating the base class from which the constructor is inherited, or by adding
an explicit constructor to the class for which the error is reported.

Closes #37914

PR Close #44615
2022-10-10 21:46:25 +00:00
..
animations fix(animations): make sure that the useAnimation function delay is applied (#47468) 2022-09-20 10:10:23 +02:00
bazel feat(core): drop support for TypeScript 4.6 and 4.7 (#47690) 2022-10-10 16:18:56 +00:00
benchpress build: clean up references to old master branch (#45856) 2022-05-04 16:23:33 -07:00
common feat(common): add <link> preload tag on server for priority img (#47343) 2022-10-10 20:48:10 +00:00
compiler fix(compiler): update element schema (#47552) 2022-10-10 21:33:45 +00:00
compiler-cli fix(compiler-cli): exclude abstract classes from strictInjectionParameters requirement (#44615) 2022-10-10 21:46:25 +00:00
core feat(common): Add automatic srcset generation to ngOptimizedImage (#47547) 2022-10-10 16:21:08 +00:00
docs docs: fix packages\docs\di\di.md (#46704) 2022-07-08 17:53:39 +00:00
elements test(elements): add a test for standalone element creation (#46475) 2022-07-18 18:20:27 +00:00
examples feat(core): support object-based DI flags in TestBed.inject() (#46761) 2022-09-27 10:09:53 -07:00
forms feat(forms): export forms utility functions: isFormArray, isFormGroup… (#47718) 2022-10-10 19:43:26 +00:00
language-service feat(language-service): Quick fix to import a component when its selector is used (#47088) 2022-10-10 21:32:43 +00:00
localize fix(localize): add polyfill in polyfills array instead of polyfills.ts (#47569) 2022-10-03 08:47:03 -07:00
misc/angular-in-memory-web-api build: update angular version of in-memory-web-api (#46344) 2022-06-13 17:40:09 +00:00
platform-browser feat(core): introduce EnvironmentProviders wrapper type (#47669) 2022-10-07 14:03:13 -07:00
platform-browser-dynamic fix(core): update isDevMode to rely on ngDevMode (#47475) 2022-09-23 13:58:45 -07:00
platform-server feat(core): introduce EnvironmentProviders wrapper type (#47669) 2022-10-07 14:03:13 -07:00
private/testing refactor(core): drop unused fields from the RootContext (#46806) 2022-08-05 09:58:06 -07:00
router feat(common): add provideLocationMocks() function to provide Location mocks (#47674) 2022-10-10 19:42:11 +00:00
service-worker fix(service-worker): include headers in requests for assets (#47260) 2022-09-06 10:03:12 -07:00
upgrade test(upgrade): demonstrate that downgraded component can be standalone (#47504) 2022-09-29 10:52:56 -07:00
zone.js build: update dependency google-closure-compiler to v20221004 (#47696) 2022-10-10 16:09:15 +00:00
BUILD.bazel build: Auto-gen tsec tsconfig files (#43440) 2021-09-17 17:17:34 +00:00
circular-deps-test.conf.js build: ignore type only imports/exports for circular dependency checks (#47017) 2022-08-18 12:06:09 -07:00
empty.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
goog.d.ts refactor(core): replace references to goog.LOCALE with goog.getLocale() (#43089) 2021-08-10 10:35:26 -07:00
license-banner.txt build: bump license year (#44590) 2022-01-04 12:05:25 -08:00
README.md docs: add doc reference to npm package readme (#33911) 2019-11-20 14:46:23 -08:00
system.d.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
tsconfig-build.json build: enable useUnknownInCatchVariables (#44679) 2022-02-01 18:17:29 +00:00
tsconfig-legacy-saucelabs.json build: bundle spec files for saucelabs legacy job (#44281) 2021-11-30 11:56:04 -05:00
tsconfig-test.json build: switch devmode output to es2015 (#44505) 2022-01-05 23:20:20 +00:00
tsconfig-tsec-base.json build: update tsconfigs to use ES2020 as target and module (#43431) 2021-10-01 18:28:42 +00:00
tsconfig.json build: enable useUnknownInCatchVariables (#44679) 2022-02-01 18:17:29 +00:00
tsec-exemption.json build: Enable tsec checks for critical packages. (#43108) 2021-09-13 14:45:57 -07:00
types.d.ts build: update to jasmine 4.0 (#45558) 2022-04-11 16:25:28 +00:00

Angular

The sources for this package are in the main Angular repo. Please file issues and pull requests against that repo.

Usage information and reference details can be found in Angular documentation.

License: MIT