@@ -16,7 +16,7 @@ import {
16
16
} from '@ember/-internals/metal' ;
17
17
import { isObject } from '@ember/-internals/utils' ;
18
18
import EmberObject from './object' ;
19
- import EmberArray , { isArray , MutableArray } from '../mixins/array' ;
19
+ import EmberArray , { MutableArray } from '../mixins/array' ;
20
20
import { assert } from '@ember/debug' ;
21
21
import { setCustomTagFor } from '@glimmer/manager' ;
22
22
import {
@@ -30,7 +30,7 @@ import {
30
30
} from '@glimmer/validator' ;
31
31
import { PropertyDidChange } from '@ember/-internals/metal/lib/property_events' ;
32
32
33
- function isMutable < T > ( obj : EmberArray < T > ) : obj is MutableArray < T > {
33
+ function isMutable < T > ( obj : T [ ] | EmberArray < T > ) : obj is T [ ] | MutableArray < T > {
34
34
return Array . isArray ( obj ) || typeof ( obj as MutableArray < T > ) . replace === 'function' ;
35
35
}
36
36
@@ -116,8 +116,8 @@ function customTagForArrayProxy(proxy: object, key: string) {
116
116
@public
117
117
*/
118
118
// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-unused-vars
119
- interface ArrayProxy < T , C extends EmberArray < T > = EmberArray < T > > extends MutableArray < T > { }
120
- class ArrayProxy < T , C extends EmberArray < T > = EmberArray < T > >
119
+ interface ArrayProxy < T , C extends EmberArray < T > | T [ ] = T [ ] > extends MutableArray < T > { }
120
+ class ArrayProxy < T , C extends EmberArray < T > | T [ ] = T [ ] >
121
121
extends EmberObject
122
122
implements PropertyDidChange
123
123
{
@@ -200,7 +200,7 @@ class ArrayProxy<T, C extends EmberArray<T> = EmberArray<T>>
200
200
201
201
// See additional docs for `replace` from `MutableArray`:
202
202
// https://api.emberjs.com/ember/release/classes/MutableArray/methods/replace?anchor=replace
203
- replace ( idx : number , amt : number , objects ?: T [ ] ) {
203
+ replace ( idx : number , amt : number , objects ?: T [ ] | EmberArray < T > ) {
204
204
assert (
205
205
'Mutating an arranged ArrayProxy is not allowed' ,
206
206
get ( this , 'arrangedContent' ) === get ( this , 'content' )
@@ -222,11 +222,11 @@ class ArrayProxy<T, C extends EmberArray<T> = EmberArray<T>>
222
222
@return {void }
223
223
@public
224
224
*/
225
- replaceContent ( idx : number , amt : number , objects ?: T [ ] ) {
225
+ replaceContent ( idx : number , amt : number , objects ?: T [ ] | EmberArray < T > ) {
226
226
let content = get ( this , 'content' ) ;
227
227
assert ( '[BUG] Called objectAtContent without content' , content ) ;
228
228
assert ( 'Mutating a non-mutable array is not allowed' , isMutable ( content ) ) ;
229
- content . replace ( idx , amt , objects ) ;
229
+ replace < T > ( content , idx , amt , objects ) ;
230
230
}
231
231
232
232
// Overriding objectAt is not supported.
@@ -312,8 +312,14 @@ class ArrayProxy<T, C extends EmberArray<T> = EmberArray<T>>
312
312
// @ts -expect-error This check is still good for ensuring correctness
313
313
assert ( "Can't set ArrayProxy's content to itself" , arrangedContent !== this ) ;
314
314
assert (
315
- `ArrayProxy expects an Array or ArrayProxy, but you passed ${ typeof arrangedContent } ` ,
316
- isArray ( arrangedContent ) || ( arrangedContent as any ) . isDestroyed
315
+ `ArrayProxy expects a native Array, EmberArray, or ArrayProxy, but you passed ${ typeof arrangedContent } ` ,
316
+ ( function ( arr : unknown ) : arr is EmberArray < unknown > {
317
+ return Array . isArray ( arr ) || EmberArray . detect ( arr ) ;
318
+ } ) ( arrangedContent )
319
+ ) ;
320
+ assert (
321
+ 'ArrayProxy expected its contents to not be destroyed' ,
322
+ ! ( arrangedContent as any ) . isDestroyed
317
323
) ;
318
324
319
325
addArrayObserver ( arrangedContent , this , ARRAY_OBSERVER_MAPPING ) ;
0 commit comments