Title: A list of suggested update to TypeScript's lib · Issue #49773 · microsoft/TypeScript · GitHub
Open Graph Title: A list of suggested update to TypeScript's lib · Issue #49773 · microsoft/TypeScript
X Title: A list of suggested update to TypeScript's lib · Issue #49773 · microsoft/TypeScript
Description: lib Update Request While working on uhyo/better-typescript-lib, I've found couples of issues in the built-in lib. While reflecting some of the changes there will cause compatibility issues and they are not included in the list below, oth...
Open Graph Description: lib Update Request While working on uhyo/better-typescript-lib, I've found couples of issues in the built-in lib. While reflecting some of the changes there will cause compatibility issues and they...
X Description: lib Update Request While working on uhyo/better-typescript-lib, I've found couples of issues in the built-in lib. While reflecting some of the changes there will cause compatibility issues and ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/49773
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"A list of suggested update to TypeScript's lib","articleBody":"## lib Update Request\r\n\r\nWhile working on [uhyo/better-typescript-lib](https://github.com/uhyo/better-typescript-lib), I've found couples of issues in the built-in lib. While reflecting some of the changes there will cause compatibility issues and they are not included in the list below, others are worth reporting because either they are serious or they are not breaking changes. Here is the list:\r\n\r\n### es2015.collection.d.ts\r\n- [x] `WeakMapConstructor`: The type of `entries` should change from `readonly [K, V][] | null` to `readonly (readonly [K, V])[] | null` to keep it consistent with `MapConstructor`\r\n\r\n### es2015.core.d.ts\r\n- [x] `{Array\u003cT>, ReadonlyArray\u003cT>}.find`:\r\n - The `this` parameter of the first parameter in the first overload is incorrectly typed `void`, which should be removed\r\n - Missing documentation for the second overload\r\n- [x] `ArrayConstructor.from`: The first parameter should be renamed `source` to keep consistency across multiple overloads from other lib files. In `es2015.iterable.d.ts` it's written `iterable: Iterable\u003cT> | ArrayLike\u003cT>` and that's misleading. It's also named `source` in the [spec text](https://tc39.es/ecma262/#sec-array.from). (The documentation should be modify to `an array-like or iterable object` too to keep it the same across all files)\r\n- [ ] ~`NumberConstructor.{isFinite, isInteger, isNaN, isSafeInteger}`: Per the [spec](https://tc39.es/ecma262/#sec-properties-of-the-number-constructor), the return type can be changed to the type predicate `number is number`~ (Excluded unless https://github.com/microsoft/TypeScript/issues/15048 resolves)\r\n- [x] `ObjectConstructor.assign`: All parameters but the first should be made writable (`{ -readonly [P in keyof T]: T[P] }`).\r\n- [x] `ObjectConstructor.{getOwnPropertySymbols, setPrototypeOf}`: 🟠 The first parameter should extends `{}`. See the **es2017.object.d.ts** section below\r\n- [x] `String.normalize`: 🟠 Per the [spec](https://tc39.es/ecma262/#sec-string.prototype.normalize), the second overload should be removed to prevent a runtime error. The first parameter should then be made optional because it's defaulted to `\"NFC\"`.\r\n\r\n### es2015.iterable.d.ts\r\n- [x] `{ArrayConstructor, %TypedArray%Constructor}.from`: See the **es2015.core.d.ts** section above\r\n\r\n### es2015.reflect.d.ts\r\nCrossed out unless @uhyo thinks them worth changing and gives some illustrations.\r\n- [ ] ~`Reflect.construct`: `newTarget` can be widen to `any`~\r\n- [ ] ~`Reflect.getPrototypeOf`: The return type can be narrowed to `object`. It's impractical to get a `null` here~\r\n- [ ] ~`Reflect.setPrototypeOf`: `proto` can be widen to `any`~\r\n\r\n### es2015.symbol.wellknown.d.ts\r\n- [ ] ~`Array\u003cT>[Symbol.unscopables]`: Should be a record.~ (Fix already available in https://github.com/microsoft/TypeScript/pull/42566)\r\n\r\n### es2017.object.d.ts\r\n- [x] `Object.getOwnPropertyDescriptors`: 🟠 Per the [spec](https://tc39.es/ecma262/#sec-object-constructor), these methods start with either a `ToObject` or `RequireObjectCoercible` operation, which throws a `TypeError` with a nullish value. Starting from TypeScript 4.8 with https://github.com/microsoft/TypeScript/pull/49119, `{}` now precisely represents any nullish value. Thus, the first parameter of these methods should now be typed `{}` to prevent runtime errors.\r\n\r\n### es2019.array.d.ts\r\n- [x] `{Array\u003cT>, ReadonlyArray\u003cT>}.flatMap`: The `This` type parameter should be removed to keep consistency with other array prototype methods in the current library\r\n\r\n### es2020.bigint.d.ts\r\n- [x] `%TypedArray%.{every, find, findIndex, some}`: The return type of the first parameter can be widen to `any` to keep consistency with other array prototype methods\r\n- [x] `%TypedArray%Constructor.from`: Missing documentation for the second overload. Also see the **es2015.core.d.ts** section above\r\n\r\n### es2021.string.d.ts\r\n- [x] `String.replaceAll`: missing `{ [Symbol.replace] }` overloads. It should be defined exactly the same as `String.replace` (The documentation should be modify to `A string or RegExp search value` too to keep it the same across all files)\r\n\r\n### es2022.object.d.ts\r\n- [x] `Object.hasOwn`: Per the [spec](https://tc39.es/ecma262/#sec-object.hasown), `o` can be widen to `{}`\r\n\r\n### es5.d.ts\r\n- [x] `ObjectConstructor.{getPrototypeOf, getOwnPropertyDescriptor, getOwnPropertyNames}`: 🟠 The first parameter should extends `{}`. See the **es2017.object.d.ts** section above\r\n- [x] `{CallableFunction, NewableFunction}.apply`: Missing documentation for the second overload\r\n- [x] `{CallableFunction, NewableFunction}.bind`: Consider rewrite it like [what we've done](https://github.com/uhyo/better-typescript-lib/blob/2bcb3179c255f50443ac437ed888a696b0adb98a/lib/lib.es5.d.ts#L157-L183)\r\n- [ ] `{Array\u003cT>, ReadonlyArray\u003cT>}.every`: 🟠 The return type of the first overload can be typed `this is { [K in keyof this]: S }` to support tuples. ~Unlike other solutions, this change is small enough that it should not break anything.~ **It does affect some important tests, so a separate PR will be opened.**\r\n- [ ] `ReadonlyArray\u003cT>.map`: 🟠 The return type can be typed `{ -readonly [K in keyof this]: U }` to support tuples. **Will be in the follow-up PR**\r\n- [ ] `Array\u003cT>.map`: 🟠 The return type can be typed `{ [K in keyof this]: U }` to support tuples. **Will be in the follow-up PR**\r\n- [x] `{Array\u003cT>, ReadonlyArray\u003cT>}.{reduce, reduceRight}`: Missing documentation for the second overload\r\n- [x] `%TypedArray%.{find, findIndex}`: The return type of the first parameter can be widen to `any` to keep consistency with other array prototype methods\r\n- [x] `%TypedArray%Constructor.from`: See the **es2015.core.d.ts** section above\r\n\r\n##### 🟠 Breaking Changes (non-exhaustive)\r\n\r\nIf the TypeScript Team is fine with certain of these changes, I am happy to open a PR for it.\r\n\r\nThanks for reading till the end. That is all.\r\n\r\n---\r\n\r\n_P.S._ I am not sure if I shouldn't put all of the above into a single issue, but opening numerous issues to reflect all of these suggestions will be too many for me. I wonder how many PRs would be comfortable to the Team and how should I split it if I'm gonna work on this.\r\n","author":{"url":"https://github.com/graphemecluster","@type":"Person","name":"graphemecluster"},"datePublished":"2022-07-04T11:16:30Z","url":"https://github.com/microsoft/TypeScript/issues/49773"}
| 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:d6a24f8d-82ce-daa7-299a-98f5341276f8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 88BA:158DF1:AC51BA:E3BAE0:6B01BCAE |
| html-safe-nonce | 136d6c21c39d36d4878c6f5f2f44a63f300fbe8e0337c7e9eead0b8191e8c765 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEJBOjE1OERGMTpBQzUxQkE6RTNCQUUwOjZCMDFCQ0FFIiwidmlzaXRvcl9pZCI6IjI4NzkwODkzNDAwNDYyMDQ2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9e647d8c343723b7cdf5eb37e468a06ebdf1083b09bdaedb5e3648d2f860e57f |
| hovercard-subject-tag | issue:1293024096 |
| 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/49773/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ac17dd1f4f2c8060b5a6ba80c9c8e1f0ccca5b0d99f258ff649a32302d2276c3/microsoft/TypeScript/issues/49773 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ac17dd1f4f2c8060b5a6ba80c9c8e1f0ccca5b0d99f258ff649a32302d2276c3/microsoft/TypeScript/issues/49773 |
| og:image:alt | lib Update Request While working on uhyo/better-typescript-lib, I've found couples of issues in the built-in lib. While reflecting some of the changes there will cause compatibility issues and they... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | graphemecluster |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width