mobxjs / mobx-state-tree

Full-featured reactive state management without the boilerplate
https://mobx-state-tree.js.org/
MIT License
6.94k stars 641 forks source link

Are Sets supported (using typescript)? #1886

Open andrewdang17 opened 2 years ago

andrewdang17 commented 2 years ago

Question

I'd like to use a Set for one of the model properties but it seems like converting the set to an array and using types.array(types.number) would be my only option. If I try to use it anyways I get an empty array and this typescript error

Type 'Set<number>' is missing the following properties from type 'number[]': length, pop, push, concat, and 24 more.ts(2740)
User.ts(11, 5): The expected type comes from property 'favoritedSongIds' which is declared here on type 'ModelCreationType<ExtractCFromProps<{ id: ISimpleType<number>; accountId: ISimpleType<number>; email: ISimpleType<string>; firstName: ISimpleType<string>; lastName: IMaybeNull<...>; favoritedSongIds: IArrayType<...>; }>>'
adamkovalsky commented 2 years ago

See #381

coolsoftwaretyler commented 1 year ago

Hey @andrewdang17 and @adamkovalsky! Sorry it took so long for anyone to get to this.

I'm going through and tagging/responding/closing out issues in MobX-State-Tree. Looks like the answer is sets are not supported, but I think we'd be happy to see a PR to that effect.

Much like #381, I'm going to mark this as help/PR accepted. Hopefully someone jumps in if they're looking for a good issue to grab. If not, I imagine a maintainer will try and get this done in the coming months/year.

If either of you is still interested, I'd be happy to get you set up with contributing. If not, no worries.

singularvoice commented 1 year ago

Hey @coolsoftwaretyler I would be happy to contribute to this issue, Can you tell me what should i do about this issue?

coolsoftwaretyler commented 1 year ago

Hey @a-hassanzadeh-h - thanks for your interest! I haven't thought too much about it, but here's what I would do to get started:

  1. See if you can replicate this behavior with a custom type. You may find some inspiration in https://github.com/mobxjs/mobx-state-tree/issues/381
  2. Once you have a working implementation, post a CodeSandbox here
  3. We can go over it, explore edge cases, limitations, etc.
  4. Once we feel good about the custom type, we can move on to PR with some tests, documentation, and implementation of a Set type in MST natively.

Let me know what you think! As a heads up, I'm going to be a little busy in the coming weeks. Sorry for any delay in responses.

chakrihacker commented 1 year ago

Hey @a-hassanzadeh-h have you picked this??

singularvoice commented 1 year ago

Hey, @chakrihacker I was busy in the last few days, But I am working on issue #1939 right now, I can work on this issue in the next week, If anybody else wants take this issue right now, it is okay, they welcome

chakrihacker commented 1 year ago

I will give it a shot then