Skip to content

TS allows adding Uint8Array item to Array<ArrayBuffer> #31311

Closed
@lll000111

Description

@lll000111

Search Terms: ArrayBuffer, Uint8Array

Code

Playground link

interface SimpleReadStream {onData: (data: ArrayBuffer) => any;}
declare function createFileReadStream(name: string): SimpleReadStream;

// CASE 1
const stream1: SimpleReadStream = createFileReadStream(name);
const blobData1: ArrayBuffer[] = [];
stream1.onData = data => {
    // TYPE MISMATCH (but no error)
    blobData1.push(new Uint8Array(data));
};

// CASE 2
const stream2: SimpleReadStream = createFileReadStream(name);
const blobData2: Uint8Array[] = [];
stream2.onData = data => {
    // TYPE MISMATCH (error as expected)
    blobData2.push(data);
};

Expected behavior:

Both test cases should result in type errors.

Actual behavior:

Only case 2 results in an error, case 1 does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions