mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 18:12:09 +08:00
fix(core): Added ObservableArray constructor declarations to allow setting multiple arguments (#9980)
This commit is contained in:

committed by
GitHub

parent
f9b52b9aac
commit
d82f3d990d
@ -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');
|
||||
|
@ -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])) {
|
||||
|
Reference in New Issue
Block a user