Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

import {InjectionToken} from '@angular/core';

export const WINDOW = new InjectionToken<Window>('WINDOW', {
export const WINDOW = new InjectionToken<typeof globalThis>('WINDOW', {
factory: () => window,
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* found in the LICENSE file at https://angular.dev/license
*/

import {Directive, ElementRef, inject, input, DestroyRef, output} from '@angular/core';
import {DestroyRef, Directive, ElementRef, inject, input, output} from '@angular/core';
import {WINDOW} from '../../application-providers/window_provider';
import {Debouncer} from '../utils/debouncer';
import {SplitComponent} from './split.component';
import {Direction} from './interface';
import {SplitComponent} from './split.component';

export const RESIZE_DEBOUNCE = 50; // in milliseconds

Expand All @@ -30,7 +30,7 @@ export type ResponsiveSplitConfig = {
export class ResponsiveSplitDirective {
private readonly host = inject(SplitComponent);
private readonly elementRef = inject(ElementRef);
private readonly window = inject<typeof globalThis>(WINDOW);
private readonly window = inject(WINDOW);

protected readonly config = input.required<ResponsiveSplitConfig>({
alias: 'ngResponsiveSplit',
Expand Down
1 change: 1 addition & 0 deletions goldens/public-api/core/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ export interface InjectDecorator {

// @public
export class InjectionToken<T> {
__brand__: T;
// @deprecated
constructor(_desc: string, options: {
providedIn: Type<any> | 'any';
Expand Down
16 changes: 15 additions & 1 deletion packages/core/src/di/injection_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ export class InjectionToken<T> {

readonly ɵprov: unknown;

/**
* This property is only used to allow the compiler to distinguish between injection tokens based
* on their generic type. If the property didn't exist, the following wouldn't result in an error:
*
* ```
* const foo = new InjectionToken<number>('foo');
* const bar: InjectionToken<string> = foo; // Should be an error.
* ```
*/
// tslint:disable-next-line:require-internal-with-underscore
declare __brand__: T;

/**
* @deprecated The `providedIn: NgModule` or `providedIn:'any'` options are deprecated. Please use the other signature.
*/
Expand Down Expand Up @@ -120,7 +132,9 @@ export class InjectionToken<T> {
* @internal
*/
get multi(): InjectionToken<Array<T>> {
return this as InjectionToken<Array<T>>;
// TODO(crisbeto): the `as unknown` here shouldn't be necessary,
// but it fails internally, likely because g3 is still on TS 4.7.
return this as unknown as InjectionToken<Array<T>>;
}

toString(): string {
Expand Down
10 changes: 5 additions & 5 deletions packages/router/src/operators/check_guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import {
CanActivateChildFn,
CanActivateFn,
CanDeactivateFn,
GuardResult,
CanLoadFn,
CanMatchFn,
Route,
GuardResult,
PartialMatchRouteSnapshot,
Route,
} from '../models';
import {redirectingNavigationError} from '../navigation_canceling_error';
import type {NavigationTransition} from '../navigation_transition';
Expand All @@ -50,8 +50,8 @@ import {
isCanMatch,
} from '../utils/type_guards';

import {prioritizedGuardValue} from './prioritized_guard_value';
import {takeUntilAbort} from '../utils/abort_signal_to_observable';
import {prioritizedGuardValue} from './prioritized_guard_value';

export function checkGuards(
forwardEvent?: (evt: Event) => void,
Expand Down Expand Up @@ -188,8 +188,8 @@ function runCanActivateChild(
const guardsMapped = d.guards.map(
(canActivateChild: CanActivateChildFn | ProviderToken<unknown>) => {
const closestInjector = d.node._environmentInjector;
const guard = getTokenOrFunctionIdentity<{canActivateChild: CanActivateChildFn}>(
canActivateChild,
const guard = getTokenOrFunctionIdentity(
canActivateChild as ProviderToken<CanActivateChildFn>,
closestInjector,
);
const guardVal = isCanActivateChild(guard)
Expand Down