Skip to content

TypedArray.subarray incorrectly expects at least 1 argument #31174

@paulmedynski

Description

@paulmedynski

TypeScript Version:
3.4.3

Search Terms:
subarray

Code

const a = new Uint8Array(50);
const b = a.subarray();

Expected behavior:
No compiler error. As per the ES6 spec:

https://www.ecma-international.org/ecma-262/6.0/#sec-%typedarray%.prototype.subarray

TypedArray.subarray() doesn't require any arguments - both begin and end are optional according to the prototype declaration. However, reading the functional steps shows end being explicitly called out as optional, whereas begin is not. At the least, the functional steps are inconsistent with the prototype declaration, but I believe TypeScript should adhere to the prototype in such a case.

Actual behavior:

src/foo.ts:566:20 - error TS2554: Expected 1-2 arguments, but got 0.

566     const result = input.subarray();
                       ~~~~~~~~~~~~~~~~

  node_modules/typescript/lib/lib.es5.d.ts:2180:14
    2180     subarray(begin: number, end?: number): Uint8Array;
                      ~~~~~~~~~~~~~
    An argument for 'begin' was not provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions