lib.d.ts: add missing TypedArray-from-iterable signatures#58188
lib.d.ts: add missing TypedArray-from-iterable signatures#58188Renegade334 wants to merge 12 commits intomicrosoft:mainfrom
Conversation
|
@typescript-bot test it |
|
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
|
@jakebailey Here are the results of running the user tests comparing Everything looks good! |
|
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@jakebailey Here are the results of running the top 400 repos comparing Everything looks good! |
8443b67 to
20c515a
Compare
sandersn
left a comment
There was a problem hiding this comment.
Looks good except I have one question about addition of Iterable in es2020.bigint
src/lib/es2020.bigint.d.ts
Outdated
| * Creates an array from an array-like or iterable object. | ||
| * @param arrayLike An array-like or iterable object to convert to an array. | ||
| */ | ||
| from(arrayLike: ArrayLike<bigint> | Iterable<bigint>): BigInt64Array; |
There was a problem hiding this comment.
why do these differ from the types in TypeArray.from? For that one, we just use Iterable.
Some guesses:
- es2020.bigint can be used without including es2015.iterable (or whatever file makes Arrays Iterable)
- Iterable is added here because it's in TypedArray.from, but ArrayLike stays for backward compatibility.
There was a problem hiding this comment.
Because in those cases, the ArrayLike overloads had already been defined in es5 prior to the introduction of iterables, so the ArrayLike signature and the Iterable signature exist as two separate overloads (eg. here and here). Since the bigint typed arrays are defined in es2020 for the first time, both need to be added here.
ArrayLike objects don't have to be iterable, so the method definitions need to accept both:
BigInt64Array.from(
// ArrayLike<number> but not iterable
{
0: 12345678,
1: 98765432,
length: 2,
},
(n: number): bigint => BigInt(n) ** 2n,
) // BigInt64Array [ 152415765279684n, 9754610558146624n ]There was a problem hiding this comment.
On that subject, though, the bigint TypedArray constructors in es2020.bigint don't look like they have a new (ArrayLike<bigint>) signature, which probably also needs addressing.
| bigIntArray = BigInt64Array.from({0: 1n, 1: 2n, 2: 3n, length: 3}); | ||
| bigIntArray = BigInt64Array.from({0: 1n, 1: 2n, 2: 3n, length: 3}, n => n * 10n); |
There was a problem hiding this comment.
re. this conversation, this is the case that necessitates keeping ArrayLike alongside Iterable.
Resolves #45198
Resolves #45199
There are stale PRs linked to these issues, but those involved wider remodelling of the array library. This should be simple enough to merge independently.