Title: Design Meeting Notes, 8/27/2024 · Issue #59778 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes, 8/27/2024 · Issue #59778 · microsoft/TypeScript
X Title: Design Meeting Notes, 8/27/2024 · Issue #59778 · microsoft/TypeScript
Description: Parameterizing TypedArrays #58573 We didn't get the chance to add the es2024 target ArrayBuffer got new members that SharedArrayBuffer does not have. Previously, SharedArrayBuffer just had two members apart from byteLength and slice, mak...
Open Graph Description: Parameterizing TypedArrays #58573 We didn't get the chance to add the es2024 target ArrayBuffer got new members that SharedArrayBuffer does not have. Previously, SharedArrayBuffer just had two memb...
X Description: Parameterizing TypedArrays #58573 We didn't get the chance to add the es2024 target ArrayBuffer got new members that SharedArrayBuffer does not have. Previously, SharedArrayBuffer just had two ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/59778
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes, 8/27/2024","articleBody":"\n# Parameterizing `TypedArray`s\n\nhttps://github.com/microsoft/TypeScript/pull/58573\n\n* We didn't get the chance to add the es2024 target \n* `ArrayBuffer` got new members that `SharedArrayBuffer` does not have.\n* Previously, `SharedArrayBuffer` just had two members apart from `byteLength` and `slice`, making them interchangeable.\n* es2024 has new members for each of these.\n * Proposed changes make them no longer interchangeable.\n * `ArrayBufferLike` is the best type to describe both.\n* Why?\n * The WebCrypto APIs only allow `ArrayBuffer`, and not `SharedArrayBuffer`,\n * e.g. `crypto.subtle.digest`\n * Also, `ArrayBuffer` is not a transferable object.\n* Makes it hard when you try to get the underlying buffer via `someUint8Array.buffer`.\n* What is the underlying idea of how these compose?\n * `ArrayBuffer` is a non-indexable span of memory. You use an \"ArrayBuffer view\" to access the memory.\n * They're not thread-safe. They're only meant to be read/written from within a single thread. If you want to share memory, you either copy the memory or transfer it entirely.\n * `SharedArrayBuffer` looks like an `ArrayBuffer` but operates over memory in a shared global heap and has has unordered but sequentially consistent writes.\n* So the idea is to parameterize each of these views over the underlying buffer type.\n\n ```ts\n interface Uint8Array\u003cBuffer extends ArrayBufferLike = ArrayBufferLike> {\n // ...\n readonly buffer: Buffer;\n\n\n // Most methods and constructors return a view with a local-only ArrayBuffer\n new (length: number): Uint8Array\u003cArrayBuffer>;\n\n // (not this one)\n new \u003cT extends ArrayBufferLike>(buffer: T, byteOffset?: number, length?: number): Uint8Array\u003cT>;\n \n new (array: ArrayLike\u003cnumber> | ArrayBuffer): Uint8Array\u003cArrayBuffer>;\n // ...\n filter(predicate: /*...*/): Uint8Array\u003cArrayBuffer>;\n }\n ```\n * **Note the above code is roughly transcribed, don't look at this as precise.**\n* Problems:\n * `Buffer` subtypes `Uint8Array`.\n * We say if you extend a base type, that base type has to have a consistent construct signature.\n * Would have to make `Buffer` generic - and to do that, we would have to start using `typesVersions` because old `UInt8Array` aren't generic.\n * Workaround: just change the returned type to `Buffer & WithArrayBufferLike\u003c...>` in the retun types of `slice` and `subarray`.\n * Why not just forward-declare `UInt8Array` as generic with an option type parameter?\n * Also, return `this` in some cases.\n* What if we fixed up stuff like `crypto.subtle.digest` etc. to accept `SharedArrayBuffer` even though they don't take those?\n * Fixes the DOM, but doesn't fix everything.\n* Could say the underlying default should be `ArrayBuffer`, not `ArrayBufferLike`.\n * We created `ArrayBufferLike` and traditionally these have never had a noticeable difference.\n\n# File Extension Rewriting, `--experimental-transform-types`/`--experimental-strip-types`, and Multi-Project Builds\n\nhttps://github.com/microsoft/TypeScript/pull/59767\n\n* Last week, we discussed rewriting relative file extensions. Had concerns, mainly around monorepo-style codebases.\n* In the meantime, we have a prototype PR.\n* Sample project\n\n ```ts\n // packages/lib/src/math.ts\n export function add(a: number, b: number) {\n return a + b;\n }\n\n // packages/lib/src/main.ts\n export * from \"./math.ts\";\n\n // packages/app/src/main.ts\n import { add } from \"@typescript-node/lib\";\n\n console.log(add(1, 2));\n ```\n* By default doesn't, work, but...\n\n ```json5\n {\n // ...\n\n \"exports\": {\n \".\": {\n \"typescript\": \"./src/main.ts\",\n \"import\": \"./dist/main.js\",\n }\n }\n }\n ```\n * Works when you run with `node --conditions typescript`.\n* Almost right, but it's not safe to publish TypeScript - if this `exports` map was published to npm and run with `node --conditions typescript`, resolution would fail within the published package.\n* One way is to erase here - but no built-in tooling to do this.\n* @colinhacks suggested namespacing on a per-package basis for publishing.\n\n ```json5\n {\n // ...\n\n \"exports\": {\n \".\": {\n \"@my-special-namespace/source\": \"./src/main.ts\",\n \"import\": \"./dist/main.js\",\n }\n }\n }\n ```\n * Can also erase these, but not sure what tools do that.\n* `moduleSuffixes`\n * Nothing special needed there, but you can't really take advantage of extension rewriting in certain circumstances.\n * You can't name something `foo.ts.android.ts`, but you also can't write `foo.ts.ts` anyway.\n * Probably will be very rare - this is mainly for React Native, and frankly really unhinged to do this.\n* Now what if projects don't take advantage of workspaces and just do a direct relative import?\n* `import { add as _add } from \"../../lib/src/main.ts`\n * Won't work if `outDir` is `dist` because it needs to be rewritten to `../../lib/dist/main.ts`.\n * It just doesn't work in some circumstances and we can give an error there.\n* You still *can* use relative imports - everything just needs to end up in the same output folder. This is, for example, how TypeScript's build works! So even we could do this.\n* For clarity: relative imports work for the following...\n\n ```\n root/\n ├── src/\n │ ├── projA/\n │ ├── projB/\n │ └── projC/\n └── dist/\n ├── projA/\n ├── projB/\n └── projC/\n ```\n\n but relative imports *do not* work for the following.\n\n ```\n projects/\n ├── projA/\n │ ├── src/\n │ └── dist/\n ├── projB/\n │ ├── src/\n │ └── dist/\n └── projC/\n ├── src/\n └── dist/\n ```\n* Sample PR to arethetypeswrong that makes everything work with `--experimental-transform-types`: https://github.com/arethetypeswrong/arethetypeswrong.github.io/pull/194\n * Notable interesting details:\n * Tests that can work against both the TS source and JS output! One just passes a specific `--conditions`.\n * Thought you needed tsconfig custom `conditions`- but you don't. TypeScript's project references are smart enough to map output files to input files.\n * Did a regex replace on relative paths - got one wrong in `#internal/getProbableExports.js` to `#internal/getProbableExports`.\n * Reinforced the need for good errors.\n* What would all this look like without project references?\n * Like one big `tsconfig.json`?\n * Not necessarily.\n * *Probably* works, just need to break things apart by packages and can't use relative paths.\n* Should Node automatically have a condition?\n * Interesting long-term, but maybe it's good for people to have a specific level of control.\n* Boilerplate-y to have to write `--conditions @my-namespace/source` and `@my-namespace/source` throughout `exports`/`imports`, but probably worth the control.\n * It's not just boilerplate though, it's more about not having all these conditions published, and not exposing this to users. Really would be ideal if these conditions could be automatically erased before publishing.\n* otherwise, we feel good about this. It's not 0-config throughout, but it feels like there is a story between the \"I can start a Node server fast\" and \"I can break my projects apart into multiple pieces\"/\"I want to publish stuff to npm\" that we feel good about.\n\n","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2024-08-27T23:13:25Z","url":"https://github.com/microsoft/TypeScript/issues/59778"}
| 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:d8878f36-e883-ae22-e2f4-5bf30730b18d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8528:1F2D:4EFED0:63AD9C:6B010B69 |
| html-safe-nonce | 3394161e40c6d0e6d647bb4e383198ad071f7b473c4425d5d2f1d31253df0c27 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTI4OjFGMkQ6NEVGRUQwOjYzQUQ5Qzo2QjAxMEI2OSIsInZpc2l0b3JfaWQiOiIxODMzMTU1MzIxNDgxMjAyNTM3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 2b30fb16dc5ccd4cca67548c7aba4ac5a2bbdaeabbd96e13ea3e6935eb6c7dd8 |
| hovercard-subject-tag | issue:2490524792 |
| 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/59778/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4c93f00e491def35ef5c27731e934db367dd5e43f0410e84e0d9346535c16f47/microsoft/TypeScript/issues/59778 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4c93f00e491def35ef5c27731e934db367dd5e43f0410e84e0d9346535c16f47/microsoft/TypeScript/issues/59778 |
| og:image:alt | Parameterizing TypedArrays #58573 We didn't get the chance to add the es2024 target ArrayBuffer got new members that SharedArrayBuffer does not have. Previously, SharedArrayBuffer just had two memb... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DanielRosenwasser |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width