Skip to content

Commit

Permalink
GetConstructorName cannot handle Angular (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanteDeRuwe committed May 2, 2022
1 parent ceeab97 commit 9203bbf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ export const noop = () => {};

export const len = (obj: { length: number }) => obj.length;

export const getConstructorName = (obj: { constructor: { name: string } } | undefined | null) => {
type ObjectWithConstructor = { constructor?: Function };
type ObjectWithZoneJsConstructor = { __zone_symbol__originalInstance?: ObjectWithConstructor }

export const getConstructorName = (obj: Object) => {
try {
const constructorName = obj?.constructor?.name;
if(constructorName) return constructorName;
} catch (e) {}
try {
return obj!.constructor.name;
const zoneJsConstructorName = (obj as ObjectWithZoneJsConstructor)?.__zone_symbol__originalInstance?.constructor?.name
if(zoneJsConstructorName) return zoneJsConstructorName;
} catch (e) {}

return '';
};

Expand Down

1 comment on commit 9203bbf

@vercel
Copy link

@vercel vercel bot commented on 9203bbf May 2, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.