File tree Expand file tree Collapse file tree 2 files changed +23
-12
lines changed
src/Clients/nodejs/src/foundation Expand file tree Collapse file tree 2 files changed +23
-12
lines changed Original file line number Diff line number Diff line change 1+ import { ObjectPal } from '../types/reflection' ;
2+
13/* @internal */
24export 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 {
Original file line number Diff line number Diff 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
2222interface 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+ }
You can’t perform that action at this time.
0 commit comments