fix(core): Added ObservableArray constructor declarations to allow setting multiple arguments (#9980)

This commit is contained in:
Dimitris-Rafail Katsampas
2022-07-30 18:23:40 +03:00
committed by GitHub
parent f9b52b9aac
commit d82f3d990d
2 changed files with 15 additions and 2 deletions

View File

@ -16,7 +16,8 @@ export const test_ObservableArray_shouldCopySourceArrayItems = function () {
export const test_ObservableArray_shouldCopyMultipleItemsAsSource = function () {
// >> observable-array-arguments
const sa = [1, 2, 3];
const array = new ObservableArray(...sa);
// Avoid appending items using spread operator as it will skip argument type check
const array = new ObservableArray(1, 2, 3);
// << observable-array-arguments
TKUnit.assertEqual(array.length, 3, 'ObservableArray length should be 3');

View File

@ -50,10 +50,22 @@ export class ObservableArray<T> extends Observable {
private _addArgs: ChangedData<T>;
private _deleteArgs: ChangedData<T>;
/**
* Create ObservableArray<T> with specified length.
*/
constructor(arrayLength?: number);
/**
* Create ObservableArray<T> from source Array<T>.
*/
constructor(args?: T[] | number) {
constructor(items: T[]);
/**
* Create ObservableArray<T> from T items.
*/
constructor(...items: T[]);
constructor(_args?: any) {
super();
if (arguments.length === 1 && Array.isArray(arguments[0])) {