Open qpwo opened 3 years ago
Could also add a ReadOnlyCursor generic type. Then a caller can cast a cursor before giving it to callee, and ensure callee does not set any data.
From afar it looks nice but I must admit I am not skilled enough in TS to know whether it would mess up with other people's code. @jacomyal any insights?
Very likely to cause typescript build errors in any codebases that have some unknown (likely irrelevant) type errors in their baobab tree. Users may want to fix those type errors but would be a pain in the ass if you're not active on a project and just wanted to update dependencies.
Two options:
npm update
from triggering the change but then new bugfixes won't go through either unless you maintain both versions. TBoabab
and TCursor
from the package for the more-strongly-typed version, then people who want that can use it intentionally. They should notice it in the auto-suggest when they start typing the import.Oh also some packages (e.g. lodash.get) explicitly type out 7 or so levels deep the return types for everything. I think it's slightly faster than this DeepIndex
and PathTree
stuff and won't cause any problems in recursive data structures, so that may be a better option. Only thing is that if you have a bunch of methods (get, set, apply, select, on('listen',…), etc) then it's quite a lot of code. Could be auto-generated but that's also a bag of worms.
All that said I still think I could take the time to do this PR proper if yall decide you'd use it
Oh you or I could also publish as a separate npm package.
@qpwo I think it would be a good first step to test the water indeed. I guess you would release something like the code presented above?
Yeah I'll give it a try
Okay giving it a shot today
Some reason didn't get linked. This is PR #513
It's nice to catch typos in keys in selectors, know the type of selected data, etc. I'll paste in my code so far here because it's not ready for a PR or anything yet. Figured I'd ask before trying to make it tidy and work well in a proper PR, do you want this functionality in the repo?
Catching typos:
Return types on get:
Immutability for apply callback:
Full code follows. still has some bugs. Will improve if there's interest.