Title: Generic TypedArray constructors have only one overload · Issue #61680 · microsoft/TypeScript · GitHub
Open Graph Title: Generic TypedArray constructors have only one overload · Issue #61680 · microsoft/TypeScript
X Title: Generic TypedArray constructors have only one overload · Issue #61680 · microsoft/TypeScript
Description: 🔎 Search Terms Uint8Array 🕗 Version & Regression Information This is the behavior in versions 5.8.3 and 5.7.3 I was unable to test this on prior versions because Uint8Array is not generic in earlier versions ⏯ Playground Link https://www...
Open Graph Description: 🔎 Search Terms Uint8Array 🕗 Version & Regression Information This is the behavior in versions 5.8.3 and 5.7.3 I was unable to test this on prior versions because Uint8Array is not generic in earlie...
X Description: 🔎 Search Terms Uint8Array 🕗 Version & Regression Information This is the behavior in versions 5.8.3 and 5.7.3 I was unable to test this on prior versions because Uint8Array is not generic in ea...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/61680
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic TypedArray constructors have only one overload","articleBody":"### 🔎 Search Terms\n\nUint8Array\n\n### 🕗 Version & Regression Information\n\n- This is the behavior in versions 5.8.3 and 5.7.3\n- I was unable to test this on prior versions because `Uint8Array` is not generic in earlier versions\n\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play/?target=11&ts=5.8.3#code/MYewdgzgLgBBIFcBOwCmMC8MyoO4wFUBLMKADgEEkkBDATwAoBGABgEoBuAKC9EllAAHOk0zY8hEuSq1G8ZGk69w0GELoAmMTnzFSlavQA8M+gCEEAM0uokAGSIBrVAD4G8lKiV9V6gMzaEnrShnQmoRbWtm4eitxAA\n\n### 💻 Code\n\n```ts\nconst source = new Uint8Array(10);\n\nconst copy1 = new Uint8Array(source); // OK\nconst copy2 = new Uint8Array\u003cArrayBufferLike>(source); // TS 2345\nconst copy3 = new Uint8Array\u003cArrayBuffer>(source); // TS 2345\n```\n\n\n### 🙁 Actual behavior\n\nOnly the generic constructor overload of `Uint8Array` is available when using `Uint8Array` with a generic parameter, i.e. the one which accepts a `TArrayBuffer` as the first argument. It is therefore not possible to pass a `Uint8Array` as the first argument without a compile error, even though this is valid.\n\n### 🙂 Expected behavior\n\nIt should be possible to use all the valid overloads of `Uint8Array` (and friends) constructor without a compiler error.\n\n### Additional information about the issue\n\nThis seems to only affect `target` value of `ES2024` or `ESNext`, but I can't figure out why from looking at the types.\n\nI assume this behaviour occurs for the same reason as given in [this comment](https://github.com/microsoft/TypeScript/issues/60745#issuecomment-2538876758). In that case I assume the fix would be adding copies of all the constructor overloads to the `Uint8ArrayConstructor` interface, but with type parameters.\n\nFor example, the following works ([TS Playground](https://www.typescriptlang.org/play/?target=11&ts=5.8.3#code/JYOwLgpgTgZghgYwgAgKqjADgIJSnATwGEB7EAZzCgFcEwSpkBvAKGXeQHpPkwALYOWSDkAK2qVkcZAhIAHAshIxkEAB6CwoAOZKAbtAA2JOABNyAGmQB3YP2QADACq58BAELUYMaA+Ry4fABbKVNTCFM2DhAIa2QAHhc8Qk9vaFU1SBBzZFcUrx8oABlgAGsUAF5c5I8C6AA+AAoojmRDCBBtfgAuZBBqIIAjaAsW5ABKXvRwHBrEvNq0qHqAbjGYuPma1MKMrJyFnegS8uQqw7rl5tb2QLdehZOIeP6hhtHWybQMWbcttyOyzWrQ2CSSAMuew6B22lyeZ2qEKWTTG7EGlwesKWHxugwIkAA8t5yBAwAB+XqvYZQHGtdqdfgUvoDam0iZTH4Lf75ZHA6KxMEXJZQ7JCIWFeHnLGFFE3KQ1TFuJ4vFkNZAAH0RPMKbK+0ywXPB2oaawAviwWLIKGBkOQSNQoEgEaD9b9CI0AIwABnGa0tZEksgUHudAtdC0adodSF9-utMnkBAATKG4uG5uLjmUIE0o46ILGrYHEwBmVPfGZczNXPMxtZAA)):\n\n```ts\ninterface Uint8ArrayConstructor {\n // this is just a copy of existing overloads, with `TArrayBuffer` param added\n new \u003cTArrayBuffer extends ArrayBufferLike = ArrayBuffer>(\n length: number,\n ): Uint8Array\u003cTArrayBuffer>;\n new \u003cTArrayBuffer extends ArrayBufferLike = ArrayBuffer>(\n array: ArrayLike\u003cnumber>,\n ): Uint8Array\u003cTArrayBuffer>;\n new \u003cTArrayBuffer extends ArrayBufferLike = ArrayBuffer>(\n buffer: ArrayBuffer,\n byteOffset?: number,\n length?: number,\n ): Uint8Array\u003cTArrayBuffer>;\n new \u003cTArrayBuffer extends ArrayBufferLike = ArrayBuffer>(\n array: ArrayLike\u003cnumber> | ArrayBuffer,\n ): Uint8Array\u003cTArrayBuffer>;\n}\n\nconst source = new Uint8Array(10);\n\nconst copy1 = new Uint8Array(source);\nconst copy2 = new Uint8Array\u003cArrayBufferLike>(source);\nconst copy3 = new Uint8Array\u003cArrayBuffer>(source);\n```\n\nI think this is basically the opposite problem to that which was fixed by #60934.","author":{"url":"https://github.com/gordonmleigh","@type":"Person","name":"gordonmleigh"},"datePublished":"2025-05-09T08:24:50Z","url":"https://github.com/microsoft/TypeScript/issues/61680"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:43c54fa5-f988-76f8-caeb-dca39d9723db |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C3E4:25598F:A5E575:DD0876:6B00EA53 |
| html-safe-nonce | 68420fe71b747558a5e0268276db81b5e8455a827366687478b1bc57214e407f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDM0U0OjI1NTk4RjpBNUU1NzU6REQwODc2OjZCMDBFQTUzIiwidmlzaXRvcl9pZCI6Ijg2OTY5NTUyODMyMDY4OTIxMTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 890d5f282f008e2362c3f6bdfc880e03d60ad5e01d02a4858709e00611ae6acb |
| hovercard-subject-tag | issue:3051406296 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/61680/issue_layout |
| twitter:image | https://opengraph.githubassets.com/418c4fd2c3123dda2f63958695d26b1fde51f47e4a91e922629f8325737600c8/microsoft/TypeScript/issues/61680 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/418c4fd2c3123dda2f63958695d26b1fde51f47e4a91e922629f8325737600c8/microsoft/TypeScript/issues/61680 |
| og:image:alt | 🔎 Search Terms Uint8Array 🕗 Version & Regression Information This is the behavior in versions 5.8.3 and 5.7.3 I was unable to test this on prior versions because Uint8Array is not generic in earlie... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gordonmleigh |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width