Skip to content

Wrong type inferred with the new genric typed arraysΒ #60638

Closed as not planned
Closed as not planned
@pfumagalli

Description

@pfumagalli

πŸ”Ž Search Terms

typed array
Uint8Array
ArrayBufferLike

πŸ•— Version & Regression Information

  • This changed between versions 5.6 and 5.7

⏯ Playground Link

No response

πŸ’» Code

This is a very simple file that exports a Uint8Array parser created by a factory method:

export type Parser<T> = (input: string) => T

function createUint8ArrayParser(): Parser<Uint8Array> {
  return (_input: unknown): Uint8Array => {
    throw new Error('Not implemented')
  }
}

export const parser = createUint8ArrayParser()

πŸ™ Actual behavior

The resulting .d.ts file looks as follows:

export type Parser<T> = (input: string) => T;
export declare const parser: Parser<Uint8Array<ArrayBufferLike>>;

The type returned for parser includes the generic version of Uint8Array which basically mean that anything depending on this export must also be at least on version 5.7.

When importing this in a project using TypeScript 5.6 we get an error:

TS(2315): Type 'Uint8Array' is not generic.

πŸ™‚ Expected behavior

The type returned for parser should be Parser<Uint8Array> and not Parser<Uint8Array<ArrayBufferLink>>

export type Parser<T> = (input: string) => T;
export declare const parser: Parser<Uint8Array>;

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions