-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(lib): define TypedArray interface #47278
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,259 +219,31 @@ interface String { | |
[Symbol.iterator](): IterableIterator<string>; | ||
} | ||
|
||
interface Int8Array { | ||
[Symbol.iterator](): IterableIterator<number>; | ||
/** | ||
* Returns an array of key, value pairs for every entry in the array | ||
*/ | ||
entries(): IterableIterator<[number, number]>; | ||
/** | ||
* Returns an list of keys in the array | ||
*/ | ||
keys(): IterableIterator<number>; | ||
/** | ||
* Returns an list of values in the array | ||
*/ | ||
values(): IterableIterator<number>; | ||
} | ||
|
||
interface Int8ArrayConstructor { | ||
new (elements: Iterable<number>): Int8Array; | ||
|
||
/** | ||
* Creates an array from an array-like or iterable object. | ||
* @param arrayLike An array-like or iterable object to convert to an array. | ||
* @param mapfn A mapping function to call on every element of the array. | ||
* @param thisArg Value of 'this' used to invoke the mapfn. | ||
*/ | ||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int8Array; | ||
} | ||
|
||
interface Uint8Array { | ||
[Symbol.iterator](): IterableIterator<number>; | ||
/** | ||
* Returns an array of key, value pairs for every entry in the array | ||
*/ | ||
entries(): IterableIterator<[number, number]>; | ||
/** | ||
* Returns an list of keys in the array | ||
*/ | ||
keys(): IterableIterator<number>; | ||
/** | ||
* Returns an list of values in the array | ||
*/ | ||
values(): IterableIterator<number>; | ||
} | ||
|
||
interface Uint8ArrayConstructor { | ||
new (elements: Iterable<number>): Uint8Array; | ||
|
||
/** | ||
* Creates an array from an array-like or iterable object. | ||
* @param arrayLike An array-like or iterable object to convert to an array. | ||
* @param mapfn A mapping function to call on every element of the array. | ||
* @param thisArg Value of 'this' used to invoke the mapfn. | ||
*/ | ||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8Array; | ||
} | ||
|
||
interface Uint8ClampedArray { | ||
[Symbol.iterator](): IterableIterator<number>; | ||
/** | ||
* Returns an array of key, value pairs for every entry in the array | ||
*/ | ||
entries(): IterableIterator<[number, number]>; | ||
|
||
/** | ||
* Returns an list of keys in the array | ||
*/ | ||
keys(): IterableIterator<number>; | ||
|
||
/** | ||
* Returns an list of values in the array | ||
*/ | ||
values(): IterableIterator<number>; | ||
} | ||
|
||
interface Uint8ClampedArrayConstructor { | ||
new (elements: Iterable<number>): Uint8ClampedArray; | ||
|
||
|
||
/** | ||
* Creates an array from an array-like or iterable object. | ||
* @param arrayLike An array-like or iterable object to convert to an array. | ||
* @param mapfn A mapping function to call on every element of the array. | ||
* @param thisArg Value of 'this' used to invoke the mapfn. | ||
*/ | ||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8ClampedArray; | ||
} | ||
|
||
interface Int16Array { | ||
[Symbol.iterator](): IterableIterator<number>; | ||
/** | ||
* Returns an array of key, value pairs for every entry in the array | ||
*/ | ||
entries(): IterableIterator<[number, number]>; | ||
|
||
/** | ||
* Returns an list of keys in the array | ||
*/ | ||
keys(): IterableIterator<number>; | ||
|
||
/** | ||
* Returns an list of values in the array | ||
*/ | ||
values(): IterableIterator<number>; | ||
} | ||
|
||
interface Int16ArrayConstructor { | ||
new (elements: Iterable<number>): Int16Array; | ||
|
||
/** | ||
* Creates an array from an array-like or iterable object. | ||
* @param arrayLike An array-like or iterable object to convert to an array. | ||
* @param mapfn A mapping function to call on every element of the array. | ||
* @param thisArg Value of 'this' used to invoke the mapfn. | ||
*/ | ||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int16Array; | ||
} | ||
|
||
interface Uint16Array { | ||
[Symbol.iterator](): IterableIterator<number>; | ||
/** | ||
* Returns an array of key, value pairs for every entry in the array | ||
*/ | ||
entries(): IterableIterator<[number, number]>; | ||
/** | ||
* Returns an list of keys in the array | ||
*/ | ||
keys(): IterableIterator<number>; | ||
/** | ||
* Returns an list of values in the array | ||
*/ | ||
values(): IterableIterator<number>; | ||
} | ||
|
||
interface Uint16ArrayConstructor { | ||
new (elements: Iterable<number>): Uint16Array; | ||
|
||
/** | ||
* Creates an array from an array-like or iterable object. | ||
* @param arrayLike An array-like or iterable object to convert to an array. | ||
* @param mapfn A mapping function to call on every element of the array. | ||
* @param thisArg Value of 'this' used to invoke the mapfn. | ||
*/ | ||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint16Array; | ||
} | ||
|
||
interface Int32Array { | ||
[Symbol.iterator](): IterableIterator<number>; | ||
/** | ||
* Returns an array of key, value pairs for every entry in the array | ||
*/ | ||
entries(): IterableIterator<[number, number]>; | ||
/** | ||
* Returns an list of keys in the array | ||
*/ | ||
keys(): IterableIterator<number>; | ||
/** | ||
* Returns an list of values in the array | ||
*/ | ||
values(): IterableIterator<number>; | ||
} | ||
|
||
interface Int32ArrayConstructor { | ||
new (elements: Iterable<number>): Int32Array; | ||
|
||
/** | ||
* Creates an array from an array-like or iterable object. | ||
* @param arrayLike An array-like or iterable object to convert to an array. | ||
* @param mapfn A mapping function to call on every element of the array. | ||
* @param thisArg Value of 'this' used to invoke the mapfn. | ||
*/ | ||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Int32Array; | ||
} | ||
|
||
interface Uint32Array { | ||
[Symbol.iterator](): IterableIterator<number>; | ||
/** | ||
* Returns an array of key, value pairs for every entry in the array | ||
*/ | ||
entries(): IterableIterator<[number, number]>; | ||
/** | ||
* Returns an list of keys in the array | ||
*/ | ||
keys(): IterableIterator<number>; | ||
/** | ||
* Returns an list of values in the array | ||
*/ | ||
values(): IterableIterator<number>; | ||
} | ||
|
||
interface Uint32ArrayConstructor { | ||
new (elements: Iterable<number>): Uint32Array; | ||
|
||
/** | ||
* Creates an array from an array-like or iterable object. | ||
* @param arrayLike An array-like or iterable object to convert to an array. | ||
* @param mapfn A mapping function to call on every element of the array. | ||
* @param thisArg Value of 'this' used to invoke the mapfn. | ||
*/ | ||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint32Array; | ||
} | ||
|
||
interface Float32Array { | ||
[Symbol.iterator](): IterableIterator<number>; | ||
/** | ||
* Returns an array of key, value pairs for every entry in the array | ||
*/ | ||
entries(): IterableIterator<[number, number]>; | ||
/** | ||
* Returns an list of keys in the array | ||
*/ | ||
keys(): IterableIterator<number>; | ||
/** | ||
* Returns an list of values in the array | ||
*/ | ||
values(): IterableIterator<number>; | ||
} | ||
|
||
interface Float32ArrayConstructor { | ||
new (elements: Iterable<number>): Float32Array; | ||
|
||
/** | ||
* Creates an array from an array-like or iterable object. | ||
* @param arrayLike An array-like or iterable object to convert to an array. | ||
* @param mapfn A mapping function to call on every element of the array. | ||
* @param thisArg Value of 'this' used to invoke the mapfn. | ||
*/ | ||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float32Array; | ||
} | ||
|
||
interface Float64Array { | ||
[Symbol.iterator](): IterableIterator<number>; | ||
interface TypedArray<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should have |
||
[Symbol.iterator](): IterableIterator<T>; | ||
/** | ||
* Returns an array of key, value pairs for every entry in the array | ||
*/ | ||
entries(): IterableIterator<[number, number]>; | ||
entries(): IterableIterator<[number, T]>; | ||
/** | ||
* Returns an list of keys in the array | ||
*/ | ||
keys(): IterableIterator<number>; | ||
/** | ||
* Returns an list of values in the array | ||
*/ | ||
values(): IterableIterator<number>; | ||
values(): IterableIterator<T>; | ||
} | ||
|
||
interface Float64ArrayConstructor { | ||
new (elements: Iterable<number>): Float64Array; | ||
interface TypedArrayConstructor<T, A extends TypedArray<T>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, I think |
||
new (elements: Iterable<T>): A; | ||
|
||
/** | ||
* Creates an array from an array-like or iterable object. | ||
* @param arrayLike An array-like or iterable object to convert to an array. | ||
* @param mapfn A mapping function to call on every element of the array. | ||
* @param thisArg Value of 'this' used to invoke the mapfn. | ||
*/ | ||
from(arrayLike: Iterable<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array; | ||
from(arrayLike: Iterable<T>, mapfn?: (v: T, k: number) => T, thisArg?: any): A; | ||
from<U>(arrayLike: Iterable<U>, mapfn?: (v: U, k: number) => T, thisArg?: any): A; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,83 +16,11 @@ interface ReadonlyArray<T> { | |
includes(searchElement: T, fromIndex?: number): boolean; | ||
} | ||
|
||
interface Int8Array { | ||
interface TypedArray<T> { | ||
/** | ||
* Determines whether an array includes a certain element, returning true or false as appropriate. | ||
* @param searchElement The element to search for. | ||
* @param fromIndex The position in this array at which to begin searching for searchElement. | ||
*/ | ||
includes(searchElement: number, fromIndex?: number): boolean; | ||
includes(searchElement: T, fromIndex?: number): boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nit: there seems to be an extra leading whitespace here |
||
} | ||
|
||
interface Uint8Array { | ||
/** | ||
* Determines whether an array includes a certain element, returning true or false as appropriate. | ||
* @param searchElement The element to search for. | ||
* @param fromIndex The position in this array at which to begin searching for searchElement. | ||
*/ | ||
includes(searchElement: number, fromIndex?: number): boolean; | ||
} | ||
|
||
interface Uint8ClampedArray { | ||
/** | ||
* Determines whether an array includes a certain element, returning true or false as appropriate. | ||
* @param searchElement The element to search for. | ||
* @param fromIndex The position in this array at which to begin searching for searchElement. | ||
*/ | ||
includes(searchElement: number, fromIndex?: number): boolean; | ||
} | ||
|
||
interface Int16Array { | ||
/** | ||
* Determines whether an array includes a certain element, returning true or false as appropriate. | ||
* @param searchElement The element to search for. | ||
* @param fromIndex The position in this array at which to begin searching for searchElement. | ||
*/ | ||
includes(searchElement: number, fromIndex?: number): boolean; | ||
} | ||
|
||
interface Uint16Array { | ||
/** | ||
* Determines whether an array includes a certain element, returning true or false as appropriate. | ||
* @param searchElement The element to search for. | ||
* @param fromIndex The position in this array at which to begin searching for searchElement. | ||
*/ | ||
includes(searchElement: number, fromIndex?: number): boolean; | ||
} | ||
|
||
interface Int32Array { | ||
/** | ||
* Determines whether an array includes a certain element, returning true or false as appropriate. | ||
* @param searchElement The element to search for. | ||
* @param fromIndex The position in this array at which to begin searching for searchElement. | ||
*/ | ||
includes(searchElement: number, fromIndex?: number): boolean; | ||
} | ||
|
||
interface Uint32Array { | ||
/** | ||
* Determines whether an array includes a certain element, returning true or false as appropriate. | ||
* @param searchElement The element to search for. | ||
* @param fromIndex The position in this array at which to begin searching for searchElement. | ||
*/ | ||
includes(searchElement: number, fromIndex?: number): boolean; | ||
} | ||
|
||
interface Float32Array { | ||
/** | ||
* Determines whether an array includes a certain element, returning true or false as appropriate. | ||
* @param searchElement The element to search for. | ||
* @param fromIndex The position in this array at which to begin searching for searchElement. | ||
*/ | ||
includes(searchElement: number, fromIndex?: number): boolean; | ||
} | ||
|
||
interface Float64Array { | ||
/** | ||
* Determines whether an array includes a certain element, returning true or false as appropriate. | ||
* @param searchElement The element to search for. | ||
* @param fromIndex The position in this array at which to begin searching for searchElement. | ||
*/ | ||
includes(searchElement: number, fromIndex?: number): boolean; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,3 @@ | ||
interface Int8ArrayConstructor { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should still also have the old types declared, just now based on |
||
new (): Int8Array; | ||
} | ||
|
||
interface Uint8ArrayConstructor { | ||
new (): Uint8Array; | ||
} | ||
|
||
interface Uint8ClampedArrayConstructor { | ||
new (): Uint8ClampedArray; | ||
} | ||
|
||
interface Int16ArrayConstructor { | ||
new (): Int16Array; | ||
} | ||
|
||
interface Uint16ArrayConstructor { | ||
new (): Uint16Array; | ||
} | ||
|
||
interface Int32ArrayConstructor { | ||
new (): Int32Array; | ||
} | ||
|
||
interface Uint32ArrayConstructor { | ||
new (): Uint32Array; | ||
} | ||
|
||
interface Float32ArrayConstructor { | ||
new (): Float32Array; | ||
} | ||
|
||
interface Float64ArrayConstructor { | ||
new (): Float64Array; | ||
interface TypedArrayConstructor<T, A extends TypedArray<T>> { | ||
new (): A; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think even though we have unified the interfaces, we should still declare them using the new
TypedArray
, likeinterface Float64Array extends TypedArray<number> { ... }
andinterface Float64ArrayConstructor extends TypedArrayConstructor<number, Float64Array> { ... }