Skip to content
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

noproxy: true type mismatch #413

Open
unrealsolver opened this issue Sep 24, 2024 · 6 comments
Open

noproxy: true type mismatch #413

unrealsolver opened this issue Sep 24, 2024 · 6 comments

Comments

@unrealsolver
Copy link

When using .get with {noproxy: true} the return type stated as Immutable<S>, however should be just S.

get(options?: { noproxy?: boolean, stealth?: boolean }): Immutable<S>;

Due to the implementation details, it would be hard to write a conditional type here. Options are:

  • Create a .getBare or .getSource method or something similar, which would have noproxy behavior
  • Change options? to positional args with conditional types
@avkonst
Copy link
Owner

avkonst commented Sep 25, 2024

Well, technically it is immutable, because changing it would almost certainly be a bug...

@unrealsolver
Copy link
Author

And totally incompatible. So I'd like to have a solution better then explicit cast with as. Not sure what would be the best. Maybe replacing Immutable with implicit agreement or something like that

@avkonst
Copy link
Owner

avkonst commented Feb 4, 2025

@speigg as your team is the biggest user of the hookstate, could you please suggest what compromise we should have here?

@avkonst
Copy link
Owner

avkonst commented Feb 4, 2025

There is also this similar: #421

@avkonst
Copy link
Owner

avkonst commented Feb 4, 2025

The only alternative is to go back and drop Immutable everywhere... not sure

@unrealsolver
Copy link
Author

Right. So Immutable* is just nominally telling that direct assignments to the state are not allowed. Which could also be achieved through these:

  • Formal convention. I think useState is just telling to use setter function instead of direct assignment in the docs and no checks if someone would try to set state with direct assignment.
  • use Proxy for the NODE_ENV=development which would just print scary error telling the user not to do direct assignments.

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

No branches or pull requests

2 participants