Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript 5.7.2: Can't extend DataView - TS2508: No Base constructor has the specified number of type arguments #60808

Closed
meszaros-lajos-gyorgy opened this issue Dec 18, 2024 · 3 comments

Comments

@meszaros-lajos-gyorgy
Copy link

🔎 Search Terms

"dataview", "ts2508", "no base constructor has the specified number of type arguments"

🕗 Version & Regression Information

  • This changed between versions 5.6.3 and 5.7.2
  • This probably changed in commit or PR Make typed arrays generic over ArrayBufferLike #59417
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about DataView and TypedArray
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.2#code/MYGwhgzhAEAa0FMAeAXBA7AJjAImFYAagJYIDu0A3gL5A

💻 Code

class X extends DataView {}

🙁 Actual behavior

error TS2508: No base constructor has the specified number of type arguments.

🙂 Expected behavior

build should run without any issues and class X should use the default constructor of DataView

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

This is working as intended, see the release notes and the PR you linked; #59417

DataView is now a generic type accepting one type argument. You don't provide a type argument.

@meszaros-lajos-gyorgy
Copy link
Author

@MartinJohns could you please provide an example? I tried the following:

class X extends DataView<Uint8Array> {}

But this gave me another error:

Type 'Uint8Array<ArrayBufferLike>' does not satisfy the constraint 'ArrayBufferLike & { BYTES_PER_ELEMENT?: undefined; }'.
  Type 'Uint8Array<ArrayBufferLike>' is not assignable to type 'ArrayBuffer & { BYTES_PER_ELEMENT?: undefined; }'.
    Type 'Uint8Array<ArrayBufferLike>' is not assignable to type '{ BYTES_PER_ELEMENT?: undefined; }'.
      Types of property 'BYTES_PER_ELEMENT' are incompatible.
        Type 'number' is not assignable to type 'undefined'.

@meszaros-lajos-gyorgy
Copy link
Author

Okay, I got it working like this:

class X extends DataView<Uint8Array['buffer']> {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants