Skip to content
Closed
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 @@ -207,11 +207,13 @@ function handleInstanceCreatedByInjectorEvent(

// if our value is an instance of a standalone component, map the injector of that standalone
// component to the component class. Otherwise, this event is a noop.
let standaloneComponent: Type<unknown> | undefined = undefined;
let standaloneComponent: Type<unknown> | undefined | null = undefined;
if (typeof value === 'object') {
standaloneComponent = value?.constructor as Type<unknown>;
standaloneComponent = value?.constructor as Type<unknown> | undefined | null;
}
if (standaloneComponent === undefined || !isStandaloneComponent(standaloneComponent)) {

// We want to also cover if `standaloneComponent === null` in addition to `undefined`
if (standaloneComponent == undefined || !isStandaloneComponent(standaloneComponent)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose adding a quick comment here to mention that we handle both null and undefined (i.e. that the == is intentional).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test would also be desirable. You may also considering widening the type of standaloneComponent to include null, as currently there's no indication that the == can make a difference vs ===

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.constructor is defined as Function | undefined, won't even consider null if I give it let standaloneComponent: Type<unknown> | undefined | null = undefined;, so I'l go with the comment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because of the (unsound) cast to Type<unknown>, which would cause any null in the declaration site to become irrelevant.

return;
}

Expand Down