Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/@ember/array/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1950,12 +1950,21 @@ if (ENV.EXTEND_PROTOTYPES.Array) {
return (arr || []) as NativeArray<T>;
};
} else {
A = function <T>(this: unknown, arr?: Array<T>) {
interface IsEmberAAble {
preventEmberA(): boolean;
}
A = function <T>(this: unknown, arr?: Array<T> | IsEmberAAble) {
assert(
'You cannot create an Ember Array with `new A()`, please update to calling A as a function: `A()`',
!(this instanceof A)
);

if (typeof (arr as IsEmberAAble)?.preventEmberA === 'function') {
if ((arr as IsEmberAAble).preventEmberA()) {
return arr as NativeArray<T>;
}
}

if (isEmberArray(arr)) {
// SAFETY: If it's a true native array and it is also an EmberArray then it should be an Ember NativeArray
return arr as NativeArray<T>;
Expand Down