Skip to content

TypedArray constructors: missing from mapping iterable #45199

Closed

Description

lib Update Request

Configuration Check

My compilation target is ESNext and my lib is the default.

Missing / Incorrect Definition

Typed array constructors (Int8Array, Float32Array, BigInt64Array, etc.) are missing an iterable overload that transforms from some non-number/bigint type to the desired number/bigint type.

Sample Code

console.log(
  Int32Array.from(new Set(["1", "2", "3"]), (value) => Number(value) ** 2).join(", ")
);
No overload matches this call.
  Overload 1 of 3, '(arrayLike: Iterable<number>, mapfn?: ((v: number, k: number) => number) | undefined, thisArg?: any): Int32Array', gave the following error.
    Argument of type 'Set<string>' is not assignable to parameter of type 'Iterable<number>'.
      The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
        Type 'IteratorResult<string, any>' is not assignable to type 'IteratorResult<number, any>'.
          Type 'IteratorYieldResult<string>' is not assignable to type 'IteratorResult<number, any>'.
            Type 'IteratorYieldResult<string>' is not assignable to type 'IteratorYieldResult<number>'.
              Type 'string' is not assignable to type 'number'.
  Overload 2 of 3, '(arrayLike: ArrayLike<unknown>, mapfn: (v: unknown, k: number) => number, thisArg?: any): Int32Array', gave the following error.
    Argument of type 'Set<string>' is not assignable to parameter of type 'ArrayLike<unknown>'.
      Property 'length' is missing in type 'Set<string>' but required in type 'ArrayLike<unknown>'.

Documentation Link

TypedArray.from() - JavaScript | MDN

Metadata

Metadata

Labels

Domain: lib.d.tsFix AvailableRescheduled

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ Proxy