-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix Typescript 5.6.x support by introducing esnext iterator helpers (#3927) #3935
Fix Typescript 5.6.x support by introducing esnext iterator helpers (#3927) #3935
Conversation
🦋 Changeset detectedLatest commit: 3e17e81 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
export function makeIterable<T, TReturn = unknown>( | ||
iterator: Iterator<T> | ||
): IteratorObject<T, TReturn> { | ||
return Object.assign(Object.create(Iterator.prototype), iterator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentionally avoiding the usage of Iterator.from due to limited availability, using this instead to conditionally add helper functions IIF they are available within runtime either natively or via polyfill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks a lot!
@mweststrate it seems that it is still not fixed. While typecheck is good, I got the following error with typescript 5.6.3 and mobx 6.13.4:
|
Most likely it's this line I believe Iterator isn't available to your environment. I am a bit unsure about compatibility requirements for mobx, but let me know more about your case maybe I missed something. |
The project I'm working on have specific setup, with mixed use of es5 and es2022 in package.json files. Quick update all the places to |
apologies @zeldigas I believe it's not working on safari apparently, thanks for reporting! working on a proper fix. |
I believe I misunderstood MDN reference reporting that Iterator.prototype is widely available but that's not the case 🤔 |
my apologies, here is the fix #3943 |
FYI: This PR introduced breaking change by utilizing This means that |
Plus 1 this is a breaking change that's disguised as a patch. Should probably be reverted, and re-introduced along with the appropriate |
apologies for the inconvenience @jansav @thisisanto Thanks for your valuable feedback. |
Working on a fix here let me know if you have any thoughts please. It might be a good idea to enable update: I've closed the "Fix" PR for now as it doesn't bring any value vs enabling |
@thisisanto @jansav to confirm: we (try to) always release against the latest version of TypeScript (which itself doesn't follow any versioning scheme), and strongly recommend to use |
Code change checklist
/docs
. For new functionality, at leastAPI.md
should be updatedyarn mobx test:performance
)Context
Fixes #3927
Purpose of the PR
TypeScript 5.6.x introduces new Iterator Helper Methods that enhance the
IterableObject
interface with methods likemap
,flatMap
,take
, anddrop
. However, when theesnext
target is enabled, MobX becomes incompatible as its current implementation lacks these methods, resulting in type errors.This PR addresses the compatibility issues by:
IterableObject
Interface: Aligning MobX’s implementation with TypeScript’s updated type definitions to prevent type errors.