Skip to content

Commit

Permalink
refactor: cleanup initializers that use ctor params (#58349)
Browse files Browse the repository at this point in the history
Fix initializer of instance members that reference identifiers declared in
the constructor.

When public class fields are enabled, such cases throw TS2729: property used
before its initialization.

PR Close #58349
  • Loading branch information
alxhub committed Oct 24, 2024
1 parent d5998da commit da9c0c5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/common/testing/src/navigation/fake_navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class FakeNavigation implements Navigation {
private canSetInitialEntry = true;

/** `EventTarget` to dispatch events. */
private eventTarget: EventTarget = this.window.document.createElement('div');
private eventTarget: EventTarget;

/** The next unique id for created entries. Replace recreates this id. */
private nextId = 0;
Expand Down Expand Up @@ -100,6 +100,7 @@ export class FakeNavigation implements Navigation {
private readonly window: Window,
startURL: `http${string}`,
) {
this.eventTarget = this.window.document.createElement('div');
// First entry.
this.setInitialEntryForTesting(startURL);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/router/src/recognize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function recognize(
const MAX_ALLOWED_REDIRECTS = 31;

export class Recognizer {
private applyRedirects = new ApplyRedirects(this.urlSerializer, this.urlTree);
private applyRedirects: ApplyRedirects;
private absoluteRedirectCount = 0;
allowRedirects = true;

Expand All @@ -88,7 +88,9 @@ export class Recognizer {
private urlTree: UrlTree,
private paramsInheritanceStrategy: ParamsInheritanceStrategy,
private readonly urlSerializer: UrlSerializer,
) {}
) {
this.applyRedirects = new ApplyRedirects(this.urlSerializer, this.urlTree);
}

private noMatchError(e: NoMatch): RuntimeError<RuntimeErrorCode.NO_MATCH> {
return new RuntimeError(
Expand Down
6 changes: 4 additions & 2 deletions packages/router/src/router_outlet_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ import {getClosestRouteInjector} from './utils/config';
export class OutletContext {
outlet: RouterOutletContract | null = null;
route: ActivatedRoute | null = null;
children = new ChildrenOutletContexts(this.rootInjector);
children: ChildrenOutletContexts;
attachRef: ComponentRef<any> | null = null;
get injector(): EnvironmentInjector {
return getClosestRouteInjector(this.route?.snapshot) ?? this.rootInjector;
}
// TODO(atscott): Only here to avoid a "breaking" change in a patch/minor. Remove in v19.
set injector(_: EnvironmentInjector) {}

constructor(private readonly rootInjector: EnvironmentInjector) {}
constructor(private readonly rootInjector: EnvironmentInjector) {
this.children = new ChildrenOutletContexts(this.rootInjector);
}
}

/**
Expand Down

0 comments on commit da9c0c5

Please sign in to comment.