GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — refactor(core): add g3-only overloads to preserve generic token types by JeanMeche · Pull Request #71762 · angular/angular Conversation
|
Type Inference SummaryUsing
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ecting or querying tokens Ports the test changes from angular#71762.
de1fc86 to
469230d
Compare
There was an error while loading. Please reload this page.
|
As a question, could this be considered a breaking change? or at least I think we might need a migration script after this is merged, since I've seen code like this many times in codebases private readonly dataService: DataService<MyItem> = inject(DataService); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
It's definitely a breaking change. It's a large breakage inside Google3. If we agree to land it. It will probably be a 2-stepper. (the 2nd step being the actual breaking change during the v23 window + a migration script alongside it). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
469230d to
789887a
Compare
e772785 to
6de5e46
Compare
72b3fb5 to
ada8b0d
Compare
Sorry, something went wrong.
There was an error while loading. Please reload this page.
ada8b0d to
81d2de1
Compare
81d2de1 to
11ef300
Compare
11ef300 to
9628aad
Compare
Adds a Bazel `--//tools/bazel:g3_mode` build setting and a `g3_test` transition rule so Angular tests can be compiled and executed locally and in CI with `g3-only` / `3p-only` sync markers active. - **`tools/bazel/patches/rules_angular_g3_mode.patch`**: Supports `--ngG3Mode` in `rules_angular`'s compiler worker, applying `g3-only` / `3p-only` markers in-memory via `fs.readFile` with an isolated `FileCache` (zero overhead and zero cache pollution for 3P builds, no file copying or `root_dir` rewrites). - **`tools/bazel/BUILD.bazel` & `tools/bazel/g3_mode.bzl`**: Defines `//tools/bazel:g3_mode`, `//tools/bazel:is_g3_mode`, and the `g3_test` transition wrapper. - **`tools/defaults.bzl`**: Forwards `--ngG3Mode` to `ts_project` and `ng_project` when `is_g3_mode` is active. - **`packages/core/test/acceptance`**: Scopes `acceptance_g3` to `**/*_g3_spec.ts` (excluded from 3P `acceptance_lib`) and adds a `g3_mode_g3_spec.ts` smoke test.
9628aad to
e844a27
Compare
In TypeScript, instantiation expressions on class constructors specialize
construct signatures (`new`) while leaving `prototype` unspecialized.
Because `ProviderToken<T>` includes `AbstractType<T>` (`{prototype: T}`),
passing specialized generic tokens to `inject()`, `Injector.get()`,
`EnvironmentInjector.get()`, `TestBed.inject()`, or signal queries caused
TypeScript to infer `T` from `prototype`, widening the return type to
`any`.
Tightening this inference is a breaking change for code relying on the
implicit `any` return type (for example,
`s: GenericService<Foo> = inject(GenericService)`). To roll this out
safely in two steps, this change adds the stricter overloads behind
`g3-only` markers so they take effect internally first, leaving external
(3P) types unchanged until the v23 breaking-change window opens. Each
overload pairs `abstract new (...args: any[]) => T` (preserving
unspecialized `ElementRef<any>`) with `abstract new (...args: never[]) => T`
(matching classes with required constructor parameters such as
`ElementRef<HTMLButtonElement>`, `TemplateRef<Ctx>`, and services using
constructor DI under `strictFunctionTypes`):
- `inject()`, `Injector.get()`, `EnvironmentInjector.get()`, and
`TestBed.inject()`: add paired `any[]`/`never[]` constructor overloads.
- Signal queries (`viewChild`, `viewChildren`, `contentChild`,
`contentChildren`): add paired `any[]`/`never[]` overloads for locators
and `read` options.
- `injector_discovery_utils.ts`: handle `NgModuleRef<unknown>` inferred
from `injector.get(viewEngine_NgModuleRef, ...)`.
- Tests: keep 3P tests preserving current `any` inference in `di_spec.ts`
and add active g3-mode specs in `di_g3_spec.ts` and
`signal_queries_g3_spec.ts`.
Related to angular#53894 and angular#48126 (will be closed once enabled in 3P for v23).
e844a27 to
917340b
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.