ArrayLike, PromiseLike

ArrayLike

lib.es5.d.ts를 살펴보면 ArrayLike는 다음과 같다.

interface ArrayLike<T> {
	readonly length: number;
	readonly [n: number]: T;
}

그렇다면 Array<T>는 어떠한 모습을 가지고 있을까

interface Array<T> {
	length: number;
	toString(): string;
	toLocaleString(): string;
	pop(): T | undefined;
	push(...items: T[]): number;
	concat(...items: ConcatArray<T>[]): T[];
	concat(...items: (T | ConcatArray<T>)[]): T[];
	join(separator?: string): string;
	// (주석 생략...) 우리가 아는 slice등의 메서드가 존재한다.
}

Array는 우리가 아는 배열로 이루어져 있지만 ArrayLike는 length와 index로만 접근하도록 구현되어 있다. 이는 배열처럼 순회할 수 있지만, 그 뿐인 유사 객체 배열이다. 대표적으로

가 있다.

PromiseLike