Skip to content

Commit

Permalink
fix, avoid using instanceof to find a component-issue (#8777)
Browse files Browse the repository at this point in the history
In many cases, the component-issue is installed as a package in
different places, causing the `instanceof` to always return `false`.
Instead, change the implementation of `getIssue` to use the
`getIssueByName`.
  • Loading branch information
davidfirst authored Apr 11, 2024
1 parent 11b95ab commit 05ced3b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions components/component-issues/issues-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,11 @@ export class IssuesList {
this._issues = this._issues.filter((issue) => issue.constructor.name !== IssueClass.name);
}

/**
* Use getIssueByName to prevent issues when getting different instances while using both bit from bvm and from the repo
* @param IssueClass
* @returns
*/
getIssue<T extends ComponentIssue>(IssueClass: { new (): T }): T | undefined {
return this._issues.find((issue) => issue instanceof IssueClass) as T | undefined;
// don't use instanceof, e.g. `this._issues.find((issue) => issue instanceof IssueClass)`
// the "component-issues" package can come from different sources, so the "instanceof" won't work.
// use only getIssueByName for this.
return this.getIssueByName(IssueClass.name as IssuesNames);
}

getIssueByName<T extends ComponentIssue>(issueType: IssuesNames): T | undefined {
Expand Down

0 comments on commit 05ced3b

Please sign in to comment.