mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
This commit replaces the old and slow `ReflectiveInjector` that was
deprecated in v5 with the new `Injector`. Note: This change was only
done in the spec files inside the `aio` folder.
While changing this, it was not possible to directly use `Injector.get`
to get the correct typing for the mocked classes. For example:
```typescript
locationService = injector.get<TestLocationService>(LocationService);
```
Fails with:
> Argument of type 'typeof LocationService' is not assignable to parameter
of type 'Type<TestLocationService> | InjectionToken<TestLocationService> |
AbstractType<TestLocationService>'.
Type 'typeof LocationService' is not assignable to type 'Type<TestLocationService>'.
Property 'searchResult' is missing in type 'LocationService' but required in type
'TestLocationService'.
Therefore, it was necessary to first convert to `unknown` and then to
`TestLocationService`.
```typescript
locationService = injector.get(LocationService) as unknown as TestLocationService;
```
PR Close #38408
|
||
|---|---|---|
| .. | ||
| custom-elements | ||
| documents | ||
| layout | ||
| navigation | ||
| search | ||
| shared | ||
| sw-updates | ||
| app.component.html | ||
| app.component.spec.ts | ||
| app.component.ts | ||
| app.module.ts | ||