File tree 1 file changed +13
-5
lines changed
1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change 5
5
6
6
import { VSBuffer } from 'vs/base/common/buffer' ;
7
7
import { regExpFlags } from 'vs/base/common/strings' ;
8
- import { URI } from 'vs/base/common/uri' ;
8
+ import { URI , UriComponents } from 'vs/base/common/uri' ;
9
9
10
10
export function stringify ( obj : any ) : string {
11
11
return JSON . stringify ( obj , replacer ) ;
@@ -33,23 +33,31 @@ function replacer(key: string, value: any): any {
33
33
return value ;
34
34
}
35
35
36
- export function revive ( obj : any , depth = 0 ) : any {
36
+
37
+ type Deserialize < T > = T extends UriComponents ? URI
38
+ : T extends object
39
+ ? Revived < T >
40
+ : T ;
41
+
42
+ export type Revived < T > = { [ K in keyof T ] : Deserialize < T [ K ] > } ;
43
+
44
+ export function revive < T = any > ( obj : any , depth = 0 ) : Revived < T > {
37
45
if ( ! obj || depth > 200 ) {
38
46
return obj ;
39
47
}
40
48
41
49
if ( typeof obj === 'object' ) {
42
50
43
51
switch ( ( < MarshalledObject > obj ) . $mid ) {
44
- case 1 : return URI . revive ( obj ) ;
45
- case 2 : return new RegExp ( obj . source , obj . flags ) ;
52
+ case 1 : return < any > URI . revive ( obj ) ;
53
+ case 2 : return < any > new RegExp ( obj . source , obj . flags ) ;
46
54
}
47
55
48
56
if (
49
57
obj instanceof VSBuffer
50
58
|| obj instanceof Uint8Array
51
59
) {
52
- return obj ;
60
+ return < any > obj ;
53
61
}
54
62
55
63
if ( Array . isArray ( obj ) ) {
You can’t perform that action at this time.
0 commit comments