@@ -37,9 +37,13 @@ type ChangeReporter = (
37
37
current ?: JsonValue ,
38
38
) => void ;
39
39
40
+ // lib.es5 PropertyKey is string | number | symbol which doesn't overlap ProxyHandler PropertyKey which is string | symbol.
41
+ // See https://github.com/microsoft/TypeScript/issues/42894
42
+ type ProxyPropertyKey = string | symbol ;
43
+
40
44
function findNode (
41
45
parent : JsonAstArray | JsonAstObject ,
42
- p : PropertyKey ,
46
+ p : ProxyPropertyKey ,
43
47
) : { node ?: JsonAstNode ; parent : JsonAstArray | JsonAstKeyValue | JsonAstObject } {
44
48
if ( parent . kind === 'object' ) {
45
49
const entry = parent . properties . find ( entry => entry . key . value === p ) ;
@@ -120,8 +124,8 @@ function create(
120
124
ast : JsonAstObject | JsonAstArray ,
121
125
path : string ,
122
126
reporter : ChangeReporter ,
123
- excluded = new Set < PropertyKey > ( ) ,
124
- included ?: Set < PropertyKey > ,
127
+ excluded = new Set < ProxyPropertyKey > ( ) ,
128
+ included ?: Set < ProxyPropertyKey > ,
125
129
base ?: object ,
126
130
) {
127
131
const cache = new Map < string , CacheEntry > ( ) ;
@@ -137,7 +141,7 @@ function create(
137
141
}
138
142
139
143
return new Proxy ( base , {
140
- getOwnPropertyDescriptor ( target : { } , p : PropertyKey ) : PropertyDescriptor | undefined {
144
+ getOwnPropertyDescriptor ( target : { } , p : ProxyPropertyKey ) : PropertyDescriptor | undefined {
141
145
const descriptor = Reflect . getOwnPropertyDescriptor ( target , p ) ;
142
146
if ( descriptor || typeof p === 'symbol' ) {
143
147
return descriptor ;
@@ -162,7 +166,7 @@ function create(
162
166
163
167
return undefined ;
164
168
} ,
165
- has ( target : { } , p : PropertyKey ) : boolean {
169
+ has ( target : { } , p : ProxyPropertyKey ) : boolean {
166
170
if ( Reflect . has ( target , p ) ) {
167
171
return true ;
168
172
} else if ( typeof p === 'symbol' || excluded . has ( p ) ) {
@@ -171,7 +175,7 @@ function create(
171
175
172
176
return cache . has ( path + '/' + escapeKey ( p ) ) || findNode ( ast , p ) !== undefined ;
173
177
} ,
174
- get ( target : { } , p : PropertyKey ) : unknown {
178
+ get ( target : { } , p : ProxyPropertyKey ) : unknown {
175
179
if ( typeof p === 'symbol' || Reflect . has ( target , p ) ) {
176
180
return Reflect . get ( target , p ) ;
177
181
} else if ( excluded . has ( p ) || ( included && ! included . has ( p ) ) ) {
@@ -206,7 +210,7 @@ function create(
206
210
207
211
return value ;
208
212
} ,
209
- set ( target : { } , p : PropertyKey , value : unknown ) : boolean {
213
+ set ( target : { } , p : ProxyPropertyKey , value : unknown ) : boolean {
210
214
if ( value === undefined ) {
211
215
// setting to undefined is equivalent to a delete
212
216
// tslint:disable-next-line: no-non-null-assertion
@@ -242,7 +246,7 @@ function create(
242
246
243
247
return true ;
244
248
} ,
245
- deleteProperty ( target : { } , p : PropertyKey ) : boolean {
249
+ deleteProperty ( target : { } , p : ProxyPropertyKey ) : boolean {
246
250
if ( typeof p === 'symbol' || Reflect . has ( target , p ) ) {
247
251
return Reflect . deleteProperty ( target , p ) ;
248
252
} else if ( excluded . has ( p ) || ( included && ! included . has ( p ) ) ) {
@@ -279,15 +283,15 @@ function create(
279
283
280
284
return true ;
281
285
} ,
282
- defineProperty ( target : { } , p : PropertyKey , attributes : PropertyDescriptor ) : boolean {
286
+ defineProperty ( target : { } , p : ProxyPropertyKey , attributes : PropertyDescriptor ) : boolean {
283
287
if ( typeof p === 'symbol' ) {
284
288
return Reflect . defineProperty ( target , p , attributes ) ;
285
289
}
286
290
287
291
return false ;
288
292
} ,
289
- ownKeys ( target : { } ) : PropertyKey [ ] {
290
- let keys : PropertyKey [ ] ;
293
+ ownKeys ( target : { } ) : ProxyPropertyKey [ ] {
294
+ let keys : ProxyPropertyKey [ ] ;
291
295
if ( ast . kind === 'object' ) {
292
296
keys = ast . properties
293
297
. map ( entry => entry . key . value )
@@ -299,7 +303,7 @@ function create(
299
303
for ( const key of cache . keys ( ) ) {
300
304
const relativeKey = key . substr ( path . length + 1 ) ;
301
305
if ( relativeKey . length > 0 && ! relativeKey . includes ( '/' ) ) {
302
- keys . push ( unescapeKey ( relativeKey ) ) ;
306
+ keys . push ( ` ${ unescapeKey ( relativeKey ) } ` ) ;
303
307
}
304
308
}
305
309
0 commit comments