Skip to content

Avoid return in constructors #2041

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

Merged
merged 1 commit into from
Feb 22, 2025

Conversation

alexvictoor
Copy link

Hello!
Happy new year 2025!
This PR removes most "return" in constructors. The only one left is in Record.js.
I have started to work on TypeScript JSDoc comments and noticed that return in constructor would make the migration of the codebase really difficult.
Also my personal opinion is that removing return in constructors increase readability.
Anyway, this PR is a prerequisite for a second PR that will come next which introduce JSDoc TypeScript comments in the codebase.
I have tried to reduce as much as possible the impact on the API but there are still some small breaking changes:
Map, List, Set are now functions. They are not classes anymore. The related classes are MapImpl, ListImpl and SetImpl. Thoses new classes are not exported so IMHO the impact for ImmutableJS users is limited.
The only issue is illustrated by the following code fragment:

m instanceof Map;    // does not work anymore
Map.isMap(m);          // should be used instead

@jdeniau
Copy link
Member

jdeniau commented Feb 10, 2025

Map, List and Set classes are exported. See

Map,
OrderedMap,
List,
Stack,
Set,

So unfortunately, I don't think that we should remove support for this.

@alexvictoor
Copy link
Author

Hello @jdeniau
For the end user, everything still works as expected regarding Map, List and Set except "instanceof". I am aware this is a breaking change but IMO this is a small one and most of all I have not found any better way to get rid of return statements in constructors.
I think this is really important to remove these return statements because once this is done, TypeScript JsDoc annotations can be added to the code quite easily.

@jdeniau jdeniau added this to the 6.0 milestone Feb 22, 2025
@jdeniau jdeniau changed the base branch from main to 6.x February 22, 2025 14:03
@jdeniau jdeniau merged commit b3ead31 into immutable-js:6.x Feb 22, 2025
5 checks passed
@jdeniau
Copy link
Member

jdeniau commented Feb 22, 2025

@alexvictoor I did merge this on the 6.x branch

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

Successfully merging this pull request may close these issues.

2 participants