Skip to content

Commit 7721db5

Browse files
Nodejs: fix collision with sentry
- decomission the augmentation in `Object.prototype.become` and replace it with a proper static method
1 parent ae372c1 commit 7721db5

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/Clients/nodejs/src/foundation/serialization/JsonConvert.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { ObjectPal } from '../types/reflection';
2+
13
/* @internal */
24
export class JsonConvert {
35
public static deserializeObject<T extends object>(json: string, type: new (...args: any[]) => T): T {
46
const result = JSON.parse(json) as T;
5-
return result.become(type);
7+
return ObjectPal.become(result, type);
68
}
79

810
public static serializeObject<T = unknown>(obj: T): string {

src/Clients/nodejs/src/foundation/types/reflection.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,29 @@ export enum Primitive {
1313
void = 'undefined',
1414
}
1515

16-
declare global {
17-
interface Object {
18-
become<T>(this: any, type: new (...args: any[]) => T): T;
19-
}
20-
}
16+
// declare global {
17+
// interface Object {
18+
// become<T>(this: any, type: new (...args: any[]) => T): T;
19+
// }
20+
// }
2121

2222
interface Becomable<T> {
2323
__proto__: any;
2424
constructor: new (...args: any[]) => T;
2525
}
2626

27-
Object.prototype.become = function <T>(this: any, type: new (...args: any[]) => T): T {
28-
const me = this as Becomable<T>;
29-
me.__proto__ = type.prototype;
30-
me.constructor = type;
31-
return this;
32-
};
27+
// Object.prototype.become = function <T>(this: any, type: new (...args: any[]) => T): T {
28+
// const me = this as Becomable<T>;
29+
// me.__proto__ = type.prototype;
30+
// me.constructor = type;
31+
// return this;
32+
// };
33+
34+
export class ObjectPal {
35+
public static become<T>(obj: any, type: new (...args: any[]) => T): T {
36+
const me = obj as Becomable<T>;
37+
me.__proto__ = type.prototype;
38+
me.constructor = type;
39+
return obj;
40+
}
41+
}

0 commit comments

Comments
 (0)